Skip to content

Commit

Permalink
release: 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwagner committed Jul 16, 2022
1 parent d71e9f4 commit cdc6259
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 342 deletions.
34 changes: 6 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# xls

Crystal bindings to libxls
Crystal bindings to [libxls](https://github.com/libxls/libxls)

## Installation

Expand All @@ -10,6 +10,7 @@ Crystal bindings to libxls
dependencies:
xls:
github: mdwagner/xls.cr
version: 0.2.0
```
2. Run `shards install`
Expand All @@ -18,41 +19,18 @@ Crystal bindings to libxls

```crystal
require "xls"
Xls::Spreadsheet # <- library entry point
```

Look at `examples/` folder for idea of usage.

TODO: Write usage instructions here

## Development

TODO: Write development instructions here

## How it works

```
Xls::Spreadsheet(1) -> Xls::Workbook(1) -> Xls::Sheets(N) -> Xls::Worksheet(N)
```
### Xls::Spreadsheet
- Represents the `.xls` file (pointer)
### Xls::Workbook
- Metadata, including accessing sheets
### Xls::Sheets
- Parses sheets and gives you valid worksheets
- Gives you sheet names and count
### Xls::Worksheet
- Content of a worksheet (rows, cols, types, etc.)
- Types
- work like JSON::Any/XML::Any/etc.
- Single type is a union of all possible types
- has different methods to assert usage: as_s/as_s?
## Contributing

1. Fork it (<https://github.com/mdwagner/xls.cr/fork>)
Expand Down
25 changes: 25 additions & 0 deletions examples/csv.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "../src/xls"

# Example: convert xls into csv
#
# Usage: [program] <xls file path>
Xls::Spreadsheet.open(Path.new(ARGV[0])) do |s|
s.worksheets.each do |ws|
ws.rows.each do |row|
row.cells.each do |cell|
value = cell.value
if str = value.as_s?
if str.includes?(",")
print "\"#{str}\""
else
print str
end
else
print cell.value.raw
end
print ","
end
print "\n"
end
end
end
62 changes: 0 additions & 62 deletions examples/wip.cr

This file was deleted.

4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: xls
version: 0.1.0
version: 0.2.0

authors:
- Michael Wagner <mdwranger@gmail.com>

crystal: '>= 1.4.1'
crystal: ">= 1.4.1"

license: MIT

Expand Down
64 changes: 1 addition & 63 deletions spec/xls/spreadsheet_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,5 @@ require "../spec_helper"
Spectator.describe Xls::Spreadsheet do
include Helpers

describe "self.xls_version" do
it "matches version pattern" do
expect(described_class.xls_version).to match(/\d\.\d\.\d/)
end
end

describe "self.open_file" do
it "initializes using LibXls.open_file" do
expect(described_class.open_file(test_fixture)).to be_a(described_class)
end
end

describe "self.new" do
context "with file path" do
it "initializes" do
expect(described_class.new(test_fixture)).to be_a(described_class)
end
end

context "with file content as string" do
it "initializes" do
content = File.read(test_fixture)
expect(described_class.new(content)).to be_a(described_class)
end
end

context "with file content as io" do
it "initializes" do
File.open(test_fixture) do |file|
expect(described_class.new(file)).to be_a(described_class)
end
end
end
end

describe "self.open" do
it "yields a Workbook" do
described_class.open(test_fixture) do |wb|
expect(wb).to be_a(Xls::Workbook)
end
end
end

describe "#close!" do
double Xls::Spreadsheet do
stub close! : Nil
end

it "closes the workbook" do
dbl = double(Xls::Spreadsheet)
allow(dbl).to receive(:close!).and_return(nil)
expect(dbl.close!).to be_nil
end
end

describe "#workbook!" do
alias XlsWorkBook = Xls::LibXls::XlsWorkBook

it "returns a raw pointer" do
instance = described_class.new(test_fixture)
expect(instance.workbook!).to be_a(Pointer(XlsWorkBook))
end
end
skip "no specs yet"
end
43 changes: 0 additions & 43 deletions spec/xls/workbook_spec.cr

This file was deleted.

Loading

0 comments on commit cdc6259

Please sign in to comment.