simple_xlsx_reader 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c495d2161ffcb0fb72029aa65b3030b01761030
4
+ data.tar.gz: 3064fcfd2ea46a5ede489cc32faff627740b569d
5
+ SHA512:
6
+ metadata.gz: 9468df9742e49b5d7c8eb830f724702b6e145dd50dc0f62e2330561091c7587364085ae850938e5853bb3ab5de744e2e87049d722e64d4989da06b5e9d0de09a
7
+ data.tar.gz: 029b31bff2274d01d43ff8498e76b6bdd7839621ed052af63c5348ec85fec90ce842831e5d739b39951a5807cf9ac6ff938343263709a17f826190afdc45d11d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.9.7
2
+
3
+ * Fix cell parsing where cells have a type, but no content
4
+ * Add a speed test; parsing performs in linear time, but a relatively
5
+ slow line :/
6
+
1
7
  ### 0.9.6
2
8
 
3
9
  * Fix worksheet indexes when worksheets have been deleted
@@ -137,7 +137,8 @@ module SimpleXlsxReader
137
137
  xcell.at_xpath('xmlns:is/xmlns:t') : xcell.at_xpath('xmlns:v')
138
138
 
139
139
  cells << begin
140
- self.class.cast(xvalue.text.strip, type, style, :shared_strings => shared_strings)
140
+ self.class.cast(xvalue && xvalue.text.strip, type, style,
141
+ :shared_strings => shared_strings)
141
142
  rescue => e
142
143
  if !SimpleXlsxReader.configuration.catch_cell_load_errors
143
144
  error = CellLoadError.new(
@@ -1,3 +1,3 @@
1
1
  module SimpleXlsxReader
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
@@ -0,0 +1,111 @@
1
+ require 'test_helper'
2
+ require 'minitest/benchmark'
3
+
4
+ describe SimpleXlsxReader do
5
+
6
+ # n is 0-indexed for us, then converted to 1-indexed for excel
7
+ def build_row(n)
8
+ n += 1
9
+ <<-XML
10
+ <row>
11
+ <c r='A#{n}' s='0'>
12
+ <v>Cell A#{n}</v>
13
+ </c>
14
+ <c r='B#{n}' s='1'>
15
+ <v>2.4</v>
16
+ </c>
17
+ <c r='C#{n}' s='2'>
18
+ <v>30687</v>
19
+ </c>
20
+ <c r='D#{n}' t='inlineStr' s='0'>
21
+ <is><t>Cell D#{n}</t></is>
22
+ </c>
23
+
24
+ <c r='E#{n}' s='0'>
25
+ <v>Cell E#{n}</v>
26
+ </c>
27
+ <c r='F#{n}' s='1'>
28
+ <v>2.4</v>
29
+ </c>
30
+ <c r='G#{n}' s='2'>
31
+ <v>30687</v>
32
+ </c>
33
+ <c r='H#{n}' t='inlineStr' s='0'>
34
+ <is><t>Cell H#{n}</t></is>
35
+ </c>
36
+
37
+ <c r='I#{n}' s='0'>
38
+ <v>Cell I#{n}</v>
39
+ </c>
40
+ <c r='J#{n}' s='1'>
41
+ <v>2.4</v>
42
+ </c>
43
+ <c r='K#{n}' s='2'>
44
+ <v>30687</v>
45
+ </c>
46
+ <c r='L#{n}' t='inlineStr' s='0'>
47
+ <is><t>Cell L#{n}</t></is>
48
+ </c>
49
+ </row>
50
+ XML
51
+ end
52
+
53
+ before do
54
+ base = Nokogiri::XML(
55
+ <<-XML
56
+ <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
57
+ <sheetData>
58
+ </sheetData>
59
+ </worksheet>
60
+ XML
61
+ )
62
+ base.at_xpath("/xmlns:worksheet/xmlns:sheetData").add_child(build_row(0))
63
+
64
+ @xml = SimpleXlsxReader::Document::Xml.new.tap do |xml|
65
+ xml.sheets = [base]
66
+
67
+ # s='0' above refers to the value of numFmtId at cellXfs index 0,
68
+ # which is in this case 'General' type
69
+ xml.styles = Nokogiri::XML(
70
+ <<-XML
71
+ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
72
+ <cellXfs count="1">
73
+ <xf numFmtId="0" />
74
+ <xf numFmtId="2" />
75
+ <xf numFmtId="14" />
76
+ </cellXfs>
77
+ </styleSheet>
78
+ XML
79
+ )
80
+ end
81
+
82
+ # Every new sheet has one more row
83
+ self.class.bench_range.each do |range|
84
+ sheet = base.clone
85
+
86
+ range.times do |n|
87
+ sheet.xpath("/xmlns:worksheet/xmlns:sheetData/xmlns:row").last.
88
+ add_next_sibling(build_row(n))
89
+ end
90
+
91
+ @xml.sheets[range] = sheet
92
+ end
93
+ end
94
+
95
+ def self.bench_range
96
+ bench_exp(1,1000)
97
+ end
98
+
99
+ bench_performance_linear 'parses sheets in linear time', 0.9999 do |n|
100
+
101
+ raise "not enough sample data; asked for #{n}, only have #{@xml.sheets.count}"\
102
+ if @xml.sheets[n].nil?
103
+
104
+ sheet = SimpleXlsxReader::Document::Mapper.new(@xml).
105
+ parse_sheet('test', @xml.sheets[n])
106
+
107
+ raise "sheet didn't parse correctly; expected #{n + 1} rows, got #{sheet.rows.count}"\
108
+ if sheet.rows.count != n + 1
109
+ end
110
+
111
+ end
Binary file
@@ -18,7 +18,8 @@ describe SimpleXlsxReader do
18
18
  [["Author Name", "Title", "Body", "Created At", "Comment Count"],
19
19
  ["Big Bird", "The Number 1", "The Greatest", Time.parse("2002-01-01 11:00:00 UTC"), 1],
20
20
  ["Big Bird", "The Number 2", "Second Best", Time.parse("2002-01-02 14:00:00 UTC"), 2],
21
- ["Big Bird", "Formula Dates", "Tricky tricky", Time.parse("2002-01-03 14:00:00 UTC"), 0]]
21
+ ["Big Bird", "Formula Dates", "Tricky tricky", Time.parse("2002-01-03 14:00:00 UTC"), 0],
22
+ ["Empty Eagress", nil, "The title, date, and comment have types, but no values", nil, nil]]
22
23
  })
23
24
  end
24
25
  end
@@ -239,20 +240,25 @@ describe SimpleXlsxReader do
239
240
  xml.sheets = [Nokogiri::XML(
240
241
  <<-XML
241
242
  <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
242
- <dimension ref="A1:C1" />
243
+ <dimension ref="A1:G1" />
243
244
  <sheetData>
244
245
  <row>
245
246
  <c r='A1' s='0'>
246
247
  <v>Cell A1</v>
247
248
  </c>
249
+
248
250
  <c r='C1' s='1'>
249
251
  <v>2.4</v>
250
252
  </c>
251
- <c r='D1' s='14'>
252
- <v>01-06-84</v>
253
+ <c r='D1' s='1' />
254
+
255
+ <c r='E1' s='2'>
256
+ <v>30687</v>
253
257
  </c>
254
- <c r='E1' t='inlineStr' s='0'>
255
- <is><t>Cell E1</t></is>
258
+ <c r='F1' s='2' />
259
+
260
+ <c r='G1' t='inlineStr' s='0'>
261
+ <is><t>Cell G1</t></is>
256
262
  </c>
257
263
  </row>
258
264
  </sheetData>
@@ -274,34 +280,42 @@ describe SimpleXlsxReader do
274
280
  XML
275
281
  )
276
282
  end
283
+ end
277
284
 
278
- before do
279
- @rows = described_class.new(xml).parse_sheet('test', xml.sheets.first).rows
280
- end
285
+ before do
286
+ @row = described_class.new(xml).parse_sheet('test', xml.sheets.first).rows[0]
287
+ end
281
288
 
282
- it "reads 'Generic' cells as strings" do
283
- @rows[0].must_equal "Cell A1"
284
- end
289
+ it "reads 'Generic' cells as strings" do
290
+ @row[0].must_equal "Cell A1"
291
+ end
285
292
 
286
- it "reads empty 'Generic' cells as nil" do
287
- @rows[1].must_equal nil
288
- end
293
+ it "reads empty 'Generic' cells as nil" do
294
+ @row[1].must_equal nil
295
+ end
289
296
 
290
- # We could expand on these type tests, but really just a couple
291
- # demonstrate that it's wired together. Type-specific tests should go
292
- # on #cast
297
+ # We could expand on these type tests, but really just a couple
298
+ # demonstrate that it's wired together. Type-specific tests should go
299
+ # on #cast
293
300
 
294
- it "reads floats" do
295
- @rows[2].must_equal 2.4
296
- end
301
+ it "reads floats" do
302
+ @row[2].must_equal 2.4
303
+ end
297
304
 
298
- it "reads dates" do
299
- @rows[3].must_equal Date.parse('Jan 6, 1984')
300
- end
305
+ it "reads empty floats as nil" do
306
+ @row[3].must_equal nil
307
+ end
301
308
 
302
- it "reads strings formatted as inlineStr" do
303
- @rows[4].must_equal 'Cell E1'
304
- end
309
+ it "reads dates" do
310
+ @row[4].must_equal Date.parse('Jan 6, 1984')
311
+ end
312
+
313
+ it "reads empty date cells as nil" do
314
+ @row[5].must_equal nil
315
+ end
316
+
317
+ it "reads strings formatted as inlineStr" do
318
+ @row[6].must_equal 'Cell G1'
305
319
  end
306
320
  end
307
321
  end
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_xlsx_reader
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.9.6
4
+ version: 0.9.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Woody Peterson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-07-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
- type: :runtime
17
15
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
16
  requirements:
20
- - - ! '>='
17
+ - - '>='
21
18
  - !ruby/object:Gem::Version
22
19
  version: '0'
20
+ type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rubyzip
32
- type: :runtime
33
29
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
30
  requirements:
36
- - - ! '>='
31
+ - - '>='
37
32
  - !ruby/object:Gem::Version
38
33
  version: '0'
34
+ type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: minitest
48
- type: :development
49
43
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
44
  requirements:
52
- - - ! '>='
45
+ - - '>='
53
46
  - !ruby/object:Gem::Version
54
47
  version: '0'
48
+ type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: pry
64
- type: :development
65
57
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
58
  requirements:
68
- - - ! '>='
59
+ - - '>='
69
60
  - !ruby/object:Gem::Version
70
61
  version: '0'
62
+ type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Read xlsx data the Ruby way
@@ -91,6 +82,7 @@ files:
91
82
  - lib/simple_xlsx_reader.rb
92
83
  - lib/simple_xlsx_reader/version.rb
93
84
  - simple_xlsx_reader.gemspec
85
+ - test/performance_test.rb
94
86
  - test/sesame_street_blog.xlsx
95
87
  - test/shared_strings.xml
96
88
  - test/simple_xlsx_reader_test.rb
@@ -98,32 +90,31 @@ files:
98
90
  - test/test_helper.rb
99
91
  homepage: ''
100
92
  licenses: []
93
+ metadata: {}
101
94
  post_install_message:
102
95
  rdoc_options: []
103
96
  require_paths:
104
97
  - lib
105
98
  required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
99
  requirements:
108
- - - ! '>='
100
+ - - '>='
109
101
  - !ruby/object:Gem::Version
110
102
  version: '0'
111
103
  required_rubygems_version: !ruby/object:Gem::Requirement
112
- none: false
113
104
  requirements:
114
- - - ! '>='
105
+ - - '>='
115
106
  - !ruby/object:Gem::Version
116
107
  version: '0'
117
108
  requirements: []
118
109
  rubyforge_project:
119
- rubygems_version: 1.8.24
110
+ rubygems_version: 2.0.3
120
111
  signing_key:
121
- specification_version: 3
112
+ specification_version: 4
122
113
  summary: Read xlsx data the Ruby way
123
114
  test_files:
115
+ - test/performance_test.rb
124
116
  - test/sesame_street_blog.xlsx
125
117
  - test/shared_strings.xml
126
118
  - test/simple_xlsx_reader_test.rb
127
119
  - test/styles.xml
128
120
  - test/test_helper.rb
129
- has_rdoc: