workbook 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19f7a4905a129fba73781bb8ef9f672573419b5b754508bc3cc28aff968d5fb8
4
- data.tar.gz: 7bd07336aaee461b7ff487c683b427ba29d717bee23731d80c1e74d1a1f7cd1e
3
+ metadata.gz: 898a4a79301299545d91cfdd5b5f1f261f4cde32337d4713256f21d894cc49f0
4
+ data.tar.gz: ee61cd9e3e3687092b5c8ca82e8aa10bf8f846553a3602ce3c46103b43ee4e9b
5
5
  SHA512:
6
- metadata.gz: 5d20a391aee1d3338f08ecddb104cca25411626787bec16a2c0a25e125efa6bbee91f79350a919afcca7d6443fac62ca34d2f2da20985e1eae3b59c73e6f6b7f
7
- data.tar.gz: 93d1ffe829d5fb3f591b9ef5244c013f4268d982f8e148893439b7788d8422f99e1449577fd708e753cb26db9029db1a08a1e46e8db0d12860e23db4124a8a82
6
+ metadata.gz: 27b2ab505f2ff035a12e839db5148337c504d81bb2c2517b2eb1ac4749df5e47f31fd281386c4c4d4880c2e24c75a3630d02c7a7bb13e5f62789543bf991f7f9
7
+ data.tar.gz: 465f709b61f96afe734739b214d1b56daa06e837ea8cd85f98c9343f9c1f7d3337409616bdc5617fa456de3718427d0d89ae89c1fa40a13efe4afbe8841ac175
data/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ### 0.9.0 (in progress)
3
+ ### 0.9.0
4
4
 
5
5
  * Dropped inheritance from Array and borrowed from the Enumerable module instead (this might break some existing implementations; please create pull request if you miss Array like functionality)
6
+ * Fix: ODS: Currency formatted cell now no longer returns String
6
7
 
7
8
  ### 0.8.1
8
9
 
data/json_test.json ADDED
@@ -0,0 +1 @@
1
+ [{"a":1,"b":2},{"a":"2012-01-01","b":null}]
@@ -138,6 +138,7 @@ module Workbook
138
138
  def parse_local_value(valuetype)
139
139
  value = CGI.unescapeHTML(@cell.xpath("text:p//text()").to_s)
140
140
  value = value == "" ? nil : value
141
+
141
142
  case valuetype
142
143
  when "integer"
143
144
  value = @cell.xpath("@office:value").to_s.to_i
@@ -146,6 +147,8 @@ module Workbook
146
147
  value = value.to_i unless /\./.match?(@cell.xpath("@office:value").to_s) # sadly most integers are typed as floats...
147
148
  when "date"
148
149
  value = DateTime.parse(@cell.xpath("@office:date-value").to_s)
150
+ when "currency"
151
+ value = @cell.xpath("@office:value").to_s.to_f
149
152
  end
150
153
  value
151
154
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Workbook
5
- VERSION = "0.8.2"
5
+ VERSION = "0.9.0"
6
6
  end
Binary file
@@ -142,6 +142,14 @@ class TestModulesCell < Minitest::Test
142
142
  assert_equal(2, t[2][2].index)
143
143
  end
144
144
 
145
+ def test_inspect
146
+ c = Workbook::Cell.new(1)
147
+ assert_equal("<Workbook::Cell @value=1 @cell_type=integer>", c.inspect)
148
+ c = Workbook::Cell.new(Date.new(2023,12,1))
149
+ assert_equal("<Workbook::Cell @value=2023-12-01 @cell_type=date>", c.inspect)
150
+ end
151
+
152
+
145
153
  def test_key
146
154
  t = Workbook::Table.new [[:a, :b, :c], [1, 2, 3], [4, 5, 6]]
147
155
  assert_equal(:c, t[2][2].key)
@@ -31,6 +31,14 @@ module Readers
31
31
  assert_equal(1.2, w.sheet.table[3][1].value)
32
32
  end
33
33
 
34
+ def test_currency
35
+ w = Workbook::Book.new
36
+ w.import File.join(File.dirname(__FILE__), "artifacts/currency_test.ods")
37
+
38
+ assert_equal(1200, w.sheet.table["H2"].value)
39
+ assert_equal(1200.4, w.sheet.table["H4"].value)
40
+ end
41
+
34
42
  def test_excel_standardized_open
35
43
  w = Workbook::Book.new
36
44
  w.import File.join(File.dirname(__FILE__), "artifacts/excel_different_types.ods")
data/test/test_sheet.rb CHANGED
@@ -71,18 +71,6 @@ class TestWorkbook < Minitest::Test
71
71
  assert_equal(false, table1 == table0)
72
72
  end
73
73
 
74
- def test_profile_speed
75
- w = Workbook::Book.new [["a", "b"], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]]
76
- require "ruby-prof"
77
- RubyProf.start
78
- w.sheet.table.each do |row|
79
- row[:a].value
80
- end
81
- result = RubyProf.stop
82
- printer = RubyProf::MultiPrinter.new(result)
83
- printer.print(path: ".", profile: "profile")
84
- end
85
-
86
74
  def test_name
87
75
  b = Workbook::Book.new [["a", "b"], [1, 2]]
88
76
  b.push Workbook::Sheet.new([["a", "b"], [2, 2]])
@@ -17,5 +17,12 @@ module Writers
17
17
  assert_equal("[{\"a\":1,\"b\":2},{\"a\":\"2012-01-01\",\"b\":null}]",
18
18
  Workbook::Table.new([["a", "b"], [1, 2], [Date.new(2012, 1, 1), nil]]).to_json)
19
19
  end
20
+
21
+ def test_write_to_json
22
+ filename = Workbook::Table.new([["a", "b"], [1, 2], [Date.new(2012, 1, 1), nil]]).write_to_json("json_test.json")
23
+ json_written = File.read(filename)
24
+ assert_equal("[{\"a\":1,\"b\":2},{\"a\":\"2012-01-01\",\"b\":null}]",json_written)
25
+
26
+ end
20
27
  end
21
28
  end
data/workbook.gemspec CHANGED
@@ -11,12 +11,11 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Workbook is a datastructure to contain books of tables (an anlogy used in e.g. Excel)"
12
12
  s.description = "Workbook contains workbooks, as in a table, contains rows, contains cells, reads/writes excel, ods and csv and tab separated files, and offers basic diffing and sorting capabilities."
13
13
  s.authors = ["Maarten Brouwers"]
14
- s.add_development_dependency "ruby-prof", "~> 0.14"
15
- s.add_development_dependency("rake", "~> 12.0")
16
- s.add_development_dependency("minitest", "~> 5.4")
14
+ s.add_development_dependency("rake", "> 12.0")
15
+ s.add_development_dependency("minitest", "> 5.4")
17
16
  s.add_development_dependency("byebug", "> 10")
18
- s.add_development_dependency("standard", "~> 0.1.0")
19
- s.add_development_dependency("simplecov", "~> 0.17.0")
17
+ s.add_development_dependency("standard", "> 1.0")
18
+ s.add_development_dependency("simplecov", "> 0.17.0")
20
19
  s.add_dependency("spreadsheet", "> 1.2")
21
20
  s.add_dependency("rchardet", ">= 1.8.0")
22
21
  s.add_dependency("json", "> 2.3")
metadata CHANGED
@@ -1,55 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Brouwers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-11 00:00:00.000000000 Z
11
+ date: 2024-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: ruby-prof
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.14'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.14'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">"
32
18
  - !ruby/object:Gem::Version
33
19
  version: '12.0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">"
39
25
  - !ruby/object:Gem::Version
40
26
  version: '12.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: minitest
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - ">"
46
32
  - !ruby/object:Gem::Version
47
33
  version: '5.4'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">"
53
39
  - !ruby/object:Gem::Version
54
40
  version: '5.4'
55
41
  - !ruby/object:Gem::Dependency
@@ -70,28 +56,28 @@ dependencies:
70
56
  name: standard
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">"
74
60
  - !ruby/object:Gem::Version
75
- version: 0.1.0
61
+ version: '1.0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">"
81
67
  - !ruby/object:Gem::Version
82
- version: 0.1.0
68
+ version: '1.0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: simplecov
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - "~>"
73
+ - - ">"
88
74
  - !ruby/object:Gem::Version
89
75
  version: 0.17.0
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - "~>"
80
+ - - ">"
95
81
  - !ruby/object:Gem::Version
96
82
  version: 0.17.0
97
83
  - !ruby/object:Gem::Dependency
@@ -209,6 +195,7 @@ files:
209
195
  - README.md
210
196
  - Rakefile
211
197
  - bin/axldiff
198
+ - json_test.json
212
199
  - lib/workbook.rb
213
200
  - lib/workbook/book.rb
214
201
  - lib/workbook/cell.rb
@@ -255,6 +242,7 @@ files:
255
242
  - test/artifacts/book_with_tabs_and_colours.xlsx
256
243
  - test/artifacts/complex_types.ods
257
244
  - test/artifacts/complex_types.xls
245
+ - test/artifacts/currency_test.ods
258
246
  - test/artifacts/excel_different_types.csv
259
247
  - test/artifacts/excel_different_types.ods
260
248
  - test/artifacts/excel_different_types.txt
@@ -337,6 +325,7 @@ test_files:
337
325
  - test/artifacts/book_with_tabs_and_colours.xlsx
338
326
  - test/artifacts/complex_types.ods
339
327
  - test/artifacts/complex_types.xls
328
+ - test/artifacts/currency_test.ods
340
329
  - test/artifacts/excel_different_types.csv
341
330
  - test/artifacts/excel_different_types.ods
342
331
  - test/artifacts/excel_different_types.txt