excel-esv 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 296eaa62bc218863be1ed8d947df92b64fa20e3a
4
- data.tar.gz: df593163f0e19a30bc541185369099e53dca4a67
3
+ metadata.gz: '091fb26ba128c0aa7edfb4626b5352932f5cd687'
4
+ data.tar.gz: 19a2ce71dff87da35950c2565c4e3f14356ccf7e
5
5
  SHA512:
6
- metadata.gz: e041a707d2f2280ed5e9281fcaa23ed0b57480fa27b6de36d31a0325c75008833e5bcde9857e6ed94a2c766f7127e5bf26c1fb2a7c2a6271e3b8b8a7548df535
7
- data.tar.gz: e22498268e8c84dc2cd459eac4d87fcf49fb20c00201726ca2f09b21c4da33ca10f6524d55891798257913b4fa901f2079f08a151a9640c6f37440f92d9ffb0a
6
+ metadata.gz: f5d61d2edd87c497fe58009ee373becca121ba5bbba4da5af46dbc2974bfede3a8f54c7d2cb25c60511c9557e12dfdb1d8912c2fb305e600c1951b4982154b19
7
+ data.tar.gz: d16b94bce839a3962cde843c50af7047c142a4c4f8f23d991a657ed6cd603dbfb799a162fe6c095048ded07c10ac0a6675f378f83f584f3a82b64d02e10731b9
@@ -1,3 +1,8 @@
1
+ # 3.0.0
2
+
3
+ * Returns the last value of any formula cells instead of returning a `Spreadsheet::Formula`.
4
+ * Returns the URL of any link cells instead of returning a `Spreadsheet::Link`.
5
+
1
6
  # 2.0.0
2
7
 
3
8
  * `parse` now returns an actual nested `Array`, not array-like `Spreadsheet::Row` records.
data/README.md CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  Ruby library/gem for Excel parsing and generation with the ease of CSV.
4
4
 
5
- Exporting CSVs because Excel generation is too complex? No more!
5
+ Exporting CSVs because Excel generation is too complex? No more! CSVs can also be difficult to open correctly, e.g. in Excel on Mac.
6
6
 
7
- CSVs can be difficult to open correctly, e.g. in Excel on Mac.
7
+ ESV will read and generate XLS files. There is currently no XLSX support, but Pull Requests are welcome.
8
+
9
+ By design, ESV only reads and writes simple values like integers, floats, strings and dates/datetimes. When parsing a spreadsheet with formulas, you will get their last value, if known.
8
10
 
9
11
 
10
12
  ## Usage
data/lib/esv.rb CHANGED
@@ -25,7 +25,15 @@ module ESV
25
25
  worksheet_count = book.worksheets.length
26
26
  raise "Expected 1 worksheet, found #{worksheet_count}." if worksheet_count > 1
27
27
 
28
- book.worksheet(0).to_a.map(&:to_a)
28
+ book.worksheet(0).to_a.map(&:to_a).map { |row|
29
+ row.map { |cell|
30
+ case cell
31
+ when Spreadsheet::Formula then cell.value
32
+ when Spreadsheet::Link then cell.href
33
+ else cell
34
+ end
35
+ }
36
+ }
29
37
  end
30
38
 
31
39
  def self.parse_file(path)
@@ -1,3 +1,3 @@
1
1
  module ESV
2
- VERSION = "2.0.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -23,7 +23,7 @@ describe ESV, ".parse" do
23
23
  }.to raise_error(/Expected 1 worksheet, found 2/)
24
24
  end
25
25
 
26
- it "ignores formatting" do
26
+ it "ignores formatting, always returning a plain array of data" do
27
27
  output = ESV.parse(excel_file_with_formatting([1, 2]))
28
28
  expect(output).to eq [
29
29
  [ 1, 2 ],
@@ -32,24 +32,68 @@ describe ESV, ".parse" do
32
32
  expect(output[0].class).to eq Array
33
33
  end
34
34
 
35
+ it "returns the last value of a formula cell" do
36
+ output = ESV.parse(excel_file_with_formula)
37
+ expect(output).to eq [
38
+ [ "one", "two" ],
39
+ ]
40
+
41
+ expect(output[0].class).to eq Array
42
+ end
43
+
44
+ it "returns the last value of a formula cell" do
45
+ output = ESV.parse(excel_file_with_formula)
46
+ expect(output).to eq [
47
+ [ "one", "two" ],
48
+ ]
49
+
50
+ expect(output[0].class).to eq Array
51
+ end
52
+
53
+ it "returns the URL of a link cell" do
54
+ output = ESV.parse(excel_file_with_link("https://example.com"))
55
+ expect(output).to eq [
56
+ [ "one", "https://example.com" ],
57
+ ]
58
+
59
+ expect(output[0][1].class).to eq String
60
+ end
61
+
35
62
  private
36
63
 
37
64
  def excel_file_with_two_worksheets
38
- book = Spreadsheet::Workbook.new
39
- book.create_worksheet
40
- book.create_worksheet
41
-
42
- data = ""
43
- fake_file = StringIO.new(data)
44
- book.write(fake_file)
45
- data
65
+ excel_file do |sheet, book|
66
+ book.create_worksheet
67
+ end
46
68
  end
47
69
 
48
70
  def excel_file_with_formatting(data)
71
+ excel_file do |sheet|
72
+ sheet.row(0).replace(data)
73
+ sheet.row(0).default_format = Spreadsheet::Format.new(color: :blue)
74
+ end
75
+ end
76
+
77
+ def excel_file_with_formula
78
+ excel_file do |sheet|
79
+ formula = Spreadsheet::Formula.new
80
+ formula.value = "two"
81
+ sheet.row(0).replace([ "one", formula ])
82
+ end
83
+ end
84
+
85
+ def excel_file_with_link(url)
86
+ excel_file do |sheet|
87
+ link = Spreadsheet::Link.new(url)
88
+ sheet.row(0).replace([ "one", link ])
89
+ end
90
+ end
91
+
92
+ def excel_file(&block)
49
93
  book = Spreadsheet::Workbook.new
50
94
  sheet = book.create_worksheet
51
- sheet.row(0).replace(data)
52
- sheet.row(0).default_format = Spreadsheet::Format.new(color: :blue)
95
+
96
+ block.call(sheet, book)
53
97
 
54
98
  data = ""
55
99
  fake_file = StringIO.new(data)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel-esv
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-19 00:00:00.000000000 Z
11
+ date: 2018-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spreadsheet