roo 1.13.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.simplecov +4 -0
  4. data/.travis.yml +13 -0
  5. data/CHANGELOG.md +515 -0
  6. data/Gemfile +16 -10
  7. data/Guardfile +24 -0
  8. data/LICENSE +3 -1
  9. data/README.md +254 -0
  10. data/Rakefile +23 -23
  11. data/examples/roo_soap_client.rb +28 -31
  12. data/examples/roo_soap_server.rb +4 -6
  13. data/examples/write_me.rb +9 -10
  14. data/lib/roo/base.rb +334 -395
  15. data/lib/roo/csv.rb +120 -113
  16. data/lib/roo/excelx/cell.rb +77 -0
  17. data/lib/roo/excelx/comments.rb +22 -0
  18. data/lib/roo/excelx/extractor.rb +22 -0
  19. data/lib/roo/excelx/relationships.rb +25 -0
  20. data/lib/roo/excelx/shared_strings.rb +37 -0
  21. data/lib/roo/excelx/sheet.rb +107 -0
  22. data/lib/roo/excelx/sheet_doc.rb +200 -0
  23. data/lib/roo/excelx/styles.rb +64 -0
  24. data/lib/roo/excelx/workbook.rb +59 -0
  25. data/lib/roo/excelx.rb +413 -597
  26. data/lib/roo/font.rb +17 -0
  27. data/lib/roo/libre_office.rb +5 -0
  28. data/lib/roo/link.rb +15 -0
  29. data/lib/roo/{openoffice.rb → open_office.rb} +681 -496
  30. data/lib/roo/spreadsheet.rb +20 -23
  31. data/lib/roo/utils.rb +78 -0
  32. data/lib/roo/version.rb +3 -0
  33. data/lib/roo.rb +18 -24
  34. data/roo.gemspec +20 -204
  35. data/spec/lib/roo/base_spec.rb +1 -4
  36. data/spec/lib/roo/csv_spec.rb +21 -13
  37. data/spec/lib/roo/excelx/format_spec.rb +7 -6
  38. data/spec/lib/roo/excelx_spec.rb +424 -11
  39. data/spec/lib/roo/libreoffice_spec.rb +16 -6
  40. data/spec/lib/roo/openoffice_spec.rb +13 -8
  41. data/spec/lib/roo/spreadsheet_spec.rb +40 -12
  42. data/spec/lib/roo/utils_spec.rb +106 -0
  43. data/spec/spec_helper.rb +2 -1
  44. data/test/test_generic_spreadsheet.rb +117 -139
  45. data/test/test_helper.rb +9 -56
  46. data/test/test_roo.rb +274 -478
  47. metadata +65 -303
  48. data/CHANGELOG +0 -417
  49. data/Gemfile.lock +0 -78
  50. data/README.markdown +0 -126
  51. data/VERSION +0 -1
  52. data/lib/roo/excel.rb +0 -355
  53. data/lib/roo/excel2003xml.rb +0 -300
  54. data/lib/roo/google.rb +0 -292
  55. data/lib/roo/roo_rails_helper.rb +0 -83
  56. data/lib/roo/worksheet.rb +0 -18
  57. data/scripts/txt2html +0 -67
  58. data/spec/lib/roo/excel2003xml_spec.rb +0 -15
  59. data/spec/lib/roo/excel_spec.rb +0 -17
  60. data/spec/lib/roo/google_spec.rb +0 -64
  61. data/test/files/1900_base.xls +0 -0
  62. data/test/files/1900_base.xlsx +0 -0
  63. data/test/files/1904_base.xls +0 -0
  64. data/test/files/1904_base.xlsx +0 -0
  65. data/test/files/Bibelbund.csv +0 -3741
  66. data/test/files/Bibelbund.ods +0 -0
  67. data/test/files/Bibelbund.xls +0 -0
  68. data/test/files/Bibelbund.xlsx +0 -0
  69. data/test/files/Bibelbund.xml +0 -62518
  70. data/test/files/Bibelbund1.ods +0 -0
  71. data/test/files/Pfand_from_windows_phone.xlsx +0 -0
  72. data/test/files/bad_excel_date.xls +0 -0
  73. data/test/files/bbu.ods +0 -0
  74. data/test/files/bbu.xls +0 -0
  75. data/test/files/bbu.xlsx +0 -0
  76. data/test/files/bbu.xml +0 -152
  77. data/test/files/bode-v1.ods.zip +0 -0
  78. data/test/files/bode-v1.xls.zip +0 -0
  79. data/test/files/boolean.csv +0 -2
  80. data/test/files/boolean.ods +0 -0
  81. data/test/files/boolean.xls +0 -0
  82. data/test/files/boolean.xlsx +0 -0
  83. data/test/files/boolean.xml +0 -112
  84. data/test/files/borders.ods +0 -0
  85. data/test/files/borders.xls +0 -0
  86. data/test/files/borders.xlsx +0 -0
  87. data/test/files/borders.xml +0 -144
  88. data/test/files/bug-numbered-sheet-names.xlsx +0 -0
  89. data/test/files/bug-row-column-fixnum-float.xls +0 -0
  90. data/test/files/bug-row-column-fixnum-float.xml +0 -127
  91. data/test/files/comments.ods +0 -0
  92. data/test/files/comments.xls +0 -0
  93. data/test/files/comments.xlsx +0 -0
  94. data/test/files/csvtypes.csv +0 -1
  95. data/test/files/datetime.ods +0 -0
  96. data/test/files/datetime.xls +0 -0
  97. data/test/files/datetime.xlsx +0 -0
  98. data/test/files/datetime.xml +0 -142
  99. data/test/files/datetime_floatconv.xls +0 -0
  100. data/test/files/datetime_floatconv.xml +0 -148
  101. data/test/files/dreimalvier.ods +0 -0
  102. data/test/files/emptysheets.ods +0 -0
  103. data/test/files/emptysheets.xls +0 -0
  104. data/test/files/emptysheets.xlsx +0 -0
  105. data/test/files/emptysheets.xml +0 -105
  106. data/test/files/excel2003.xml +0 -21140
  107. data/test/files/false_encoding.xls +0 -0
  108. data/test/files/false_encoding.xml +0 -132
  109. data/test/files/file_item_error.xlsx +0 -0
  110. data/test/files/formula.ods +0 -0
  111. data/test/files/formula.xls +0 -0
  112. data/test/files/formula.xlsx +0 -0
  113. data/test/files/formula.xml +0 -134
  114. data/test/files/formula_parse_error.xls +0 -0
  115. data/test/files/formula_parse_error.xml +0 -1833
  116. data/test/files/formula_string_error.xlsx +0 -0
  117. data/test/files/html-escape.ods +0 -0
  118. data/test/files/link.xls +0 -0
  119. data/test/files/link.xlsx +0 -0
  120. data/test/files/matrix.ods +0 -0
  121. data/test/files/matrix.xls +0 -0
  122. data/test/files/named_cells.ods +0 -0
  123. data/test/files/named_cells.xls +0 -0
  124. data/test/files/named_cells.xlsx +0 -0
  125. data/test/files/no_spreadsheet_file.txt +0 -1
  126. data/test/files/numbers1.csv +0 -18
  127. data/test/files/numbers1.ods +0 -0
  128. data/test/files/numbers1.xls +0 -0
  129. data/test/files/numbers1.xlsx +0 -0
  130. data/test/files/numbers1.xml +0 -312
  131. data/test/files/numeric-link.xlsx +0 -0
  132. data/test/files/only_one_sheet.ods +0 -0
  133. data/test/files/only_one_sheet.xls +0 -0
  134. data/test/files/only_one_sheet.xlsx +0 -0
  135. data/test/files/only_one_sheet.xml +0 -67
  136. data/test/files/paragraph.ods +0 -0
  137. data/test/files/paragraph.xls +0 -0
  138. data/test/files/paragraph.xlsx +0 -0
  139. data/test/files/paragraph.xml +0 -127
  140. data/test/files/prova.xls +0 -0
  141. data/test/files/ric.ods +0 -0
  142. data/test/files/simple_spreadsheet.ods +0 -0
  143. data/test/files/simple_spreadsheet.xls +0 -0
  144. data/test/files/simple_spreadsheet.xlsx +0 -0
  145. data/test/files/simple_spreadsheet.xml +0 -225
  146. data/test/files/simple_spreadsheet_from_italo.ods +0 -0
  147. data/test/files/simple_spreadsheet_from_italo.xls +0 -0
  148. data/test/files/simple_spreadsheet_from_italo.xml +0 -242
  149. data/test/files/so_datetime.csv +0 -7
  150. data/test/files/style.ods +0 -0
  151. data/test/files/style.xls +0 -0
  152. data/test/files/style.xlsx +0 -0
  153. data/test/files/style.xml +0 -154
  154. data/test/files/time-test.csv +0 -2
  155. data/test/files/time-test.ods +0 -0
  156. data/test/files/time-test.xls +0 -0
  157. data/test/files/time-test.xlsx +0 -0
  158. data/test/files/time-test.xml +0 -131
  159. data/test/files/type_excel.ods +0 -0
  160. data/test/files/type_excel.xlsx +0 -0
  161. data/test/files/type_excelx.ods +0 -0
  162. data/test/files/type_excelx.xls +0 -0
  163. data/test/files/type_openoffice.xls +0 -0
  164. data/test/files/type_openoffice.xlsx +0 -0
  165. data/test/files/whitespace.ods +0 -0
  166. data/test/files/whitespace.xls +0 -0
  167. data/test/files/whitespace.xlsx +0 -0
  168. data/test/files/whitespace.xml +0 -184
  169. data/test/rm_sub_test.rb +0 -12
  170. data/test/rm_test.rb +0 -7
  171. data/website/index.html +0 -385
  172. data/website/index.txt +0 -423
  173. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  174. data/website/stylesheets/screen.css +0 -130
  175. data/website/template.rhtml +0 -48
@@ -1,37 +1,450 @@
1
+ # encoding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Roo::Excelx do
5
+ subject(:xlsx) do
6
+ Roo::Excelx.new(path)
7
+ end
8
+
4
9
  describe '.new' do
5
- subject {
6
- Roo::Excelx.new('test/files/numbers1.xlsx')
7
- }
10
+ let(:path) { 'test/files/numeric-link.xlsx' }
8
11
 
9
12
  it 'creates an instance' do
10
13
  expect(subject).to be_a(Roo::Excelx)
11
14
  end
12
15
 
13
16
  context 'given a file with missing rels' do
14
- subject {
15
- Roo::Excelx.new('test/files/file_item_error.xlsx')
16
- }
17
+ let(:path) { 'test/files/file_item_error.xlsx' }
18
+
19
+ it 'creates an instance' do
20
+ expect(subject).to be_a(Roo::Excelx)
21
+ end
22
+ end
23
+
24
+ context 'with more cells than specified max' do
25
+ let(:path) { 'test/files/only_one_sheet.xlsx' }
26
+
27
+ it 'raises an appropriate error' do
28
+ expect { Roo::Excelx.new(path, cell_max: 1) }.to raise_error(Roo::Excelx::ExceedsMaxError)
29
+ end
30
+ end
31
+
32
+ context 'with fewer cells than specified max' do
33
+ let(:path) { 'test/files/only_one_sheet.xlsx' }
34
+
35
+ it 'creates an instance' do
36
+ expect(Roo::Excelx.new(path, cell_max: 100)).to be_a(Roo::Excelx)
37
+ end
38
+ end
39
+
40
+ context 'file path is a Pathname' do
41
+ let(:path) { Pathname.new('test/files/file_item_error.xlsx') }
17
42
 
18
43
  it 'creates an instance' do
19
44
  expect(subject).to be_a(Roo::Excelx)
20
45
  end
21
46
  end
47
+
22
48
  end
23
49
 
24
50
  describe '#cell' do
25
51
  context 'for a link cell' do
26
52
  context 'with numeric contents' do
27
- subject {
28
- Roo::Excelx.new('test/files/numeric-link.xlsx').cell('A', 1)
29
- }
53
+ let(:path) { 'test/files/numeric-link.xlsx' }
54
+
55
+ subject do
56
+ xlsx.cell('A', 1)
57
+ end
30
58
 
31
59
  it 'returns a link with the number as a string value' do
32
- expect(subject).to be_a(Spreadsheet::Link)
33
- expect(subject).to eq("8675309.0")
60
+ expect(subject).to be_a(Roo::Link)
61
+ expect(subject).to eq('8675309.0')
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'for a non-existent cell' do
67
+ let(:path) { 'test/files/numeric-link.xlsx' }
68
+ it 'return nil' do
69
+ expect(xlsx.cell('AAA', 999)).to eq nil
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '#parse' do
75
+ let(:path) { 'test/files/numeric-link.xlsx' }
76
+
77
+ context 'with a columns hash' do
78
+ context 'when not present in the sheet' do
79
+ it 'does not raise' do
80
+ expect do
81
+ xlsx.sheet(0).parse(
82
+ this: 'This',
83
+ that: 'That'
84
+ )
85
+ end.to raise_error("Couldn't find header row.")
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '#parse_with_clean_option' do
92
+ let(:path) { 'test/files/parse_with_clean_option.xlsx' }
93
+ let(:options) { {clean: true} }
94
+
95
+ context 'with clean: true' do
96
+
97
+ it 'does not raise' do
98
+ expect do
99
+ xlsx.parse(options)
100
+ end.not_to raise_error
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '#parse_unicode_with_clean_option' do
106
+ let(:path) { 'test/files/parse_clean_with_unicode.xlsx' }
107
+ let(:options) { {clean: true, name: 'Name'} }
108
+
109
+ context 'with clean: true' do
110
+
111
+ it 'returns a non empty string' do
112
+ expect(xlsx.parse(options).last[:name]).to eql('凯')
113
+ end
114
+ end
115
+ end
116
+
117
+
118
+
119
+
120
+ describe '#sheets' do
121
+ let(:path) { 'test/files/numbers1.xlsx' }
122
+
123
+ it 'returns the expected result' do
124
+ expect(subject.sheets).to eq ["Tabelle1", "Name of Sheet 2", "Sheet3", "Sheet4", "Sheet5"]
125
+ end
126
+
127
+ describe 'only showing visible sheets' do
128
+ let(:path) { 'test/files/hidden_sheets.xlsx' }
129
+
130
+ it 'returns the expected result' do
131
+ expect(Roo::Excelx.new(path, only_visible_sheets: true).sheets).to eq ["VisibleSheet1"]
132
+ end
133
+ end
134
+ end
135
+
136
+ describe '#sheet_for' do
137
+ let(:path) { 'test/files/numbers1.xlsx' }
138
+
139
+ # This is kinda gross
140
+ it 'returns the expected result' do
141
+ expect(subject.sheet_for("Tabelle1").instance_variable_get("@name")).to eq "Tabelle1"
142
+ end
143
+ end
144
+
145
+ describe '#row' do
146
+ let(:path) { 'test/files/numbers1.xlsx' }
147
+
148
+ it 'returns the expected result' do
149
+ expect(subject.row(1, "Sheet5")).to eq [1.0, 5.0, 5.0, nil, nil]
150
+ end
151
+ end
152
+
153
+ describe '#column' do
154
+ let(:path) { 'test/files/numbers1.xlsx' }
155
+
156
+ it 'returns the expected result' do
157
+ expect(subject.column(1, "Sheet5")).to eq [1.0, 2.0, 3.0, Date.new(2007,11,21), 42.0, "ABC"]
158
+ end
159
+ end
160
+
161
+ describe '#first_row' do
162
+ let(:path) { 'test/files/numbers1.xlsx' }
163
+
164
+ it 'returns the expected result' do
165
+ expect(subject.first_row("Sheet5")).to eq 1
166
+ end
167
+ end
168
+
169
+ describe '#last_row' do
170
+ let(:path) { 'test/files/numbers1.xlsx' }
171
+
172
+ it 'returns the expected result' do
173
+ expect(subject.last_row("Sheet5")).to eq 6
174
+ end
175
+ end
176
+
177
+ describe '#first_column' do
178
+ let(:path) { 'test/files/numbers1.xlsx' }
179
+
180
+ it 'returns the expected result' do
181
+ expect(subject.first_column("Sheet5")).to eq 1
182
+ end
183
+ end
184
+
185
+ describe '#last_column' do
186
+ let(:path) { 'test/files/numbers1.xlsx' }
187
+
188
+ it 'returns the expected result' do
189
+ expect(subject.last_column("Sheet5")).to eq 5
190
+ end
191
+ end
192
+
193
+ describe '#set' do
194
+
195
+ before do
196
+ subject.set(1, 2, "Foo", "Sheet5")
197
+ end
198
+
199
+ let(:path) { 'test/files/numbers1.xlsx' }
200
+ let(:cell) { subject.cell(1, 2, "Sheet5") }
201
+
202
+ it 'returns the expected result' do
203
+ expect(cell).to eq "Foo"
204
+ end
205
+ end
206
+
207
+ describe '#formula' do
208
+ let(:path) { 'test/files/formula.xlsx' }
209
+
210
+ it 'returns the expected result' do
211
+ expect(subject.formula(1, 1, "Sheet1")).to eq nil
212
+ expect(subject.formula(7, 2, "Sheet1")).to eq "SUM($A$1:B6)"
213
+ expect(subject.formula(1000, 2000, "Sheet1")).to eq nil
214
+ end
215
+ end
216
+
217
+ describe '#formula?' do
218
+ let(:path) { 'test/files/formula.xlsx' }
219
+
220
+ it 'returns the expected result' do
221
+ expect(subject.formula?(1, 1, "Sheet1")).to eq false
222
+ expect(subject.formula?(7, 2, "Sheet1")).to eq true
223
+ expect(subject.formula?(1000, 2000, "Sheet1")).to eq false
224
+ end
225
+ end
226
+
227
+ describe '#formulas' do
228
+ let(:path) { 'test/files/formula.xlsx' }
229
+
230
+ it 'returns the expected result' do
231
+ expect(subject.formulas("Sheet1")).to eq [[7, 1, "SUM(A1:A6)"], [7, 2, "SUM($A$1:B6)"]]
232
+ end
233
+ end
234
+
235
+ describe '#font' do
236
+ let(:path) { 'test/files/style.xlsx' }
237
+
238
+ it 'returns the expected result' do
239
+ expect(subject.font(1, 1).bold?).to eq true
240
+ expect(subject.font(1, 1).italic?).to eq false
241
+ expect(subject.font(1, 1).underline?).to eq false
242
+
243
+ expect(subject.font(7, 1).bold?).to eq false
244
+ expect(subject.font(7, 1).italic?).to eq true
245
+ expect(subject.font(7, 1).underline?).to eq true
246
+ expect(subject.font(1000, 2000)).to eq nil
247
+ end
248
+ end
249
+
250
+ describe '#celltype' do
251
+ let(:path) { 'test/files/numbers1.xlsx' }
252
+
253
+ it 'returns the expected result' do
254
+ expect(subject.celltype(1, 1, "Sheet4")).to eq :date
255
+ expect(subject.celltype(1, 2, "Sheet4")).to eq :float
256
+ expect(subject.celltype(6, 2, "Sheet5")).to eq :string
257
+ expect(subject.celltype(1000, 2000, "Sheet5")).to eq nil
258
+ end
259
+ end
260
+
261
+ describe '#excelx_type' do
262
+ let(:path) { 'test/files/numbers1.xlsx' }
263
+
264
+ it 'returns the expected result' do
265
+ expect(subject.excelx_type(1, 1, "Sheet5")).to eq [:numeric_or_formula, "General"]
266
+ expect(subject.excelx_type(6, 2, "Sheet5")).to eq :string
267
+ expect(subject.excelx_type(1000, 2000, "Sheet5")).to eq nil
268
+ end
269
+ end
270
+
271
+ describe '#excelx_value' do
272
+ let(:path) { 'test/files/numbers1.xlsx' }
273
+
274
+ it 'returns the expected result' do
275
+ # These values are the index in the shared strings table, might be a better
276
+ # way to get these rather than hardcoding.
277
+ expect(subject.excelx_value(1, 1, "Sheet5")).to eq "1"
278
+ expect(subject.excelx_value(6, 2, "Sheet5")).to eq "16"
279
+ expect(subject.excelx_value(6000, 2000, "Sheet5")).to eq nil
280
+ end
281
+ end
282
+
283
+ describe '#excelx_format' do
284
+ let(:path) { 'test/files/style.xlsx' }
285
+
286
+ it 'returns the expected result' do
287
+ # These are the index of the style for a given document
288
+ # might be more reliable way to get this info.
289
+ expect(subject.excelx_format(1, 1)).to eq "General"
290
+ expect(subject.excelx_format(2, 2)).to eq "0.00"
291
+ expect(subject.excelx_format(5000, 1000)).to eq nil
292
+ end
293
+ end
294
+
295
+ describe '#empty?' do
296
+ let(:path) { 'test/files/style.xlsx' }
297
+
298
+ it 'returns the expected result' do
299
+ # These are the index of the style for a given document
300
+ # might be more reliable way to get this info.
301
+ expect(subject.empty?(1, 1)).to eq false
302
+ expect(subject.empty?(13, 1)).to eq true
303
+ end
304
+ end
305
+
306
+ describe '#label' do
307
+ let(:path) { 'test/files/named_cells.xlsx' }
308
+
309
+ it 'returns the expected result' do
310
+ expect(subject.label("berta")).to eq [4, 2, "Sheet1"]
311
+ expect(subject.label("dave")).to eq [nil, nil, nil]
312
+ end
313
+ end
314
+
315
+ describe '#labels' do
316
+ let(:path) { 'test/files/named_cells.xlsx' }
317
+
318
+ it 'returns the expected result' do
319
+ expect(subject.labels).to eq [["anton", [5, 3, "Sheet1"]], ["berta", [4, 2, "Sheet1"]], ["caesar", [7, 2, "Sheet1"]]]
320
+ end
321
+ end
322
+
323
+ describe '#hyperlink?' do
324
+ let(:path) { 'test/files/link.xlsx' }
325
+
326
+ it 'returns the expected result' do
327
+ expect(subject.hyperlink?(1, 1)).to eq true
328
+ expect(subject.hyperlink?(1, 2)).to eq false
329
+ end
330
+ end
331
+
332
+ describe '#hyperlink' do
333
+ let(:path) { 'test/files/link.xlsx' }
334
+
335
+ it 'returns the expected result' do
336
+ expect(subject.hyperlink(1, 1)).to eq "http://www.google.com"
337
+ expect(subject.hyperlink(1, 2)).to eq nil
338
+ end
339
+ end
340
+
341
+ describe '#comment' do
342
+ let(:path) { 'test/files/comments.xlsx' }
343
+
344
+ it 'returns the expected result' do
345
+ expect(subject.comment(4, 2)).to eq "Kommentar fuer B4"
346
+ expect(subject.comment(1, 2)).to eq nil
347
+ end
348
+ end
349
+
350
+ describe '#comment?' do
351
+ let(:path) { 'test/files/comments.xlsx' }
352
+
353
+ it 'returns the expected result' do
354
+ expect(subject.comment?(4, 2)).to eq true
355
+ expect(subject.comment?(1, 2)).to eq false
356
+ end
357
+ end
358
+
359
+ describe '#comments' do
360
+ let(:path) { 'test/files/comments.xlsx' }
361
+
362
+ it 'returns the expected result' do
363
+ expect(subject.comments).to eq [[4, 2, "Kommentar fuer B4"], [5, 2, "Kommentar fuer B5"]]
364
+ end
365
+ end
366
+
367
+ # nil, nil, nil, nil, nil
368
+ # nil, nil, nil, nil, nil
369
+ # Date Start time End time Pause Sum Comment
370
+ # 2007-05-07 9.25 10.25 0 1 Task 1
371
+ # 2007-05-07 10.75 12.50 0 1.75 Task 1
372
+ # 2007-05-07 18.00 19.00 0 1 Task 2
373
+ # 2007-05-08 9.25 10.25 0 1 Task 2
374
+ # 2007-05-08 14.50 15.50 0 1 Task 3
375
+ # 2007-05-08 8.75 9.25 0 0.5 Task 3
376
+ # 2007-05-14 21.75 22.25 0 0.5 Task 3
377
+ # 2007-05-14 22.50 23.00 0 0.5 Task 3
378
+ # 2007-05-15 11.75 12.75 0 1 Task 3
379
+ # 2007-05-07 10.75 10.75 0 0 Task 1
380
+ # nil
381
+ describe '#each_row_streaming' do
382
+ let(:path) { 'test/files/simple_spreadsheet.xlsx' }
383
+
384
+ let(:expected_rows) do
385
+ [
386
+ [nil, nil, nil, nil, nil],
387
+ [nil, nil, nil, nil, nil],
388
+ ["Date", "Start time", "End time", "Pause", "Sum", "Comment", nil, nil],
389
+ [Date.new(2007, 5, 7), 9.25, 10.25, 0.0, 1.0, "Task 1"],
390
+ [Date.new(2007, 5, 7), 10.75, 12.50, 0.0, 1.75, "Task 1"],
391
+ [Date.new(2007, 5, 7), 18.0, 19.0, 0.0, 1.0, "Task 2"],
392
+ [Date.new(2007, 5, 8), 9.25, 10.25, 0.0, 1.0, "Task 2"],
393
+ [Date.new(2007, 5, 8), 14.5, 15.5, 0.0, 1.0, "Task 3"],
394
+ [Date.new(2007, 5, 8), 8.75, 9.25, 0.0, 0.5, "Task 3"],
395
+ [Date.new(2007, 5, 14), 21.75, 22.25, 0.0, 0.5, "Task 3"],
396
+ [Date.new(2007, 5, 14), 22.5, 23.0, 0.0, 0.5, "Task 3"],
397
+ [Date.new(2007, 5, 15), 11.75, 12.75, 0.0, 1.0, "Task 3"],
398
+ [Date.new(2007, 5, 7), 10.75, 10.75, 0.0, 0.0, "Task 1"],
399
+ [nil]
400
+ ]
401
+ end
402
+
403
+ it 'returns the expected result' do
404
+ index = 0
405
+ subject.each_row_streaming do |row|
406
+ expect(row.map(&:value)).to eq expected_rows[index]
407
+ index += 1
408
+ end
409
+ end
410
+
411
+ context 'with max_rows options' do
412
+ it 'returns the expected result' do
413
+ index = 0
414
+ subject.each_row_streaming(max_rows: 3) do |row|
415
+ expect(row.map(&:value)).to eq expected_rows[index]
416
+ index += 1
417
+ end
418
+ # Expect this to get incremented one time more than max (because of the increment at the end of the block)
419
+ # but it should not be near expected_rows.size
420
+ expect(index).to eq 4
421
+ end
422
+ end
423
+
424
+ context 'with offset option' do
425
+ let(:offset) { 3 }
426
+
427
+ it 'returns the expected result' do
428
+ index = 0
429
+ subject.each_row_streaming(offset: offset) do |row|
430
+ expect(row.map(&:value)).to eq expected_rows[index + offset]
431
+ index += 1
432
+ end
433
+ expect(index).to eq 11
434
+ end
435
+ end
436
+
437
+ context 'with offset and max_rows options' do
438
+ let(:offset) { 3 }
439
+ let(:max_rows) { 3 }
440
+
441
+ it 'returns the expected result' do
442
+ index = 0
443
+ subject.each_row_streaming(offset: offset, max_rows: max_rows) do |row|
444
+ expect(row.map(&:value)).to eq expected_rows[index + offset]
445
+ index += 1
34
446
  end
447
+ expect(index).to eq 4
35
448
  end
36
449
  end
37
450
  end
@@ -2,18 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  describe Roo::LibreOffice do
4
4
  describe '.new' do
5
- subject {
5
+ subject do
6
6
  Roo::LibreOffice.new('test/files/numbers1.ods')
7
- }
7
+ end
8
8
 
9
9
  it 'creates an instance' do
10
10
  expect(subject).to be_a(Roo::LibreOffice)
11
11
  end
12
12
  end
13
- end
14
13
 
15
- describe Roo::Libreoffice do
16
- it 'is an alias of LibreOffice' do
17
- expect(Roo::Libreoffice).to eq(Roo::LibreOffice)
14
+ describe '#sheets' do
15
+ let(:path) { 'test/files/hidden_sheets.ods' }
16
+
17
+ describe 'showing all sheets' do
18
+ it 'returns the expected result' do
19
+ expect(Roo::LibreOffice.new(path).sheets).to eq ["HiddenSheet1", "VisibleSheet1", "HiddenSheet2"]
20
+ end
21
+ end
22
+
23
+ describe 'only showing visible sheets' do
24
+ it 'returns the expected result' do
25
+ expect(Roo::LibreOffice.new(path, only_visible_sheets: true).sheets).to eq ["VisibleSheet1"]
26
+ end
27
+ end
18
28
  end
19
29
  end
@@ -2,20 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  describe Roo::OpenOffice do
4
4
  describe '.new' do
5
- subject {
5
+ subject do
6
6
  Roo::OpenOffice.new('test/files/numbers1.ods')
7
- }
7
+ end
8
8
 
9
9
  it 'creates an instance' do
10
10
  expect(subject).to be_a(Roo::OpenOffice)
11
11
  end
12
- end
13
12
 
14
- # OpenOffice is an alias of LibreOffice. See libreoffice_spec.
15
- end
13
+ context 'file path is a Pathname' do
14
+ subject do
15
+ Roo::OpenOffice.new(Pathname.new('test/files/numbers1.ods'))
16
+ end
16
17
 
17
- describe Roo::Openoffice do
18
- it 'is an alias of LibreOffice' do
19
- expect(Roo::Openoffice).to eq(Roo::OpenOffice)
18
+ it 'creates an instance' do
19
+ expect(subject).to be_a(Roo::OpenOffice)
20
+ end
21
+ end
22
+
20
23
  end
24
+
25
+ # OpenOffice is an alias of LibreOffice. See libreoffice_spec.
21
26
  end
@@ -2,15 +2,34 @@ require 'spec_helper'
2
2
 
3
3
  describe Roo::Spreadsheet do
4
4
  describe '.open' do
5
+ context 'when the file name includes a space' do
6
+ let(:filename) { 'great scott.xlsx' }
7
+
8
+ it 'loads the proper type' do
9
+ expect(Roo::Excelx).to receive(:new).with(filename, {})
10
+ Roo::Spreadsheet.open(filename)
11
+ end
12
+ end
13
+
5
14
  context 'when the file extension is uppercase' do
6
- let(:filename) { 'file.XLS' }
15
+ let(:filename) { 'file.XLSX' }
7
16
 
8
17
  it 'loads the proper type' do
9
- expect(Roo::Excel).to receive(:new).with(filename, {})
18
+ expect(Roo::Excelx).to receive(:new).with(filename, {})
10
19
  Roo::Spreadsheet.open(filename)
11
20
  end
12
21
  end
13
22
 
23
+ context 'for a tempfile' do
24
+ let(:tempfile) { Tempfile.new('foo.csv') }
25
+ let(:filename) { tempfile.path }
26
+
27
+ it 'loads the proper type' do
28
+ expect(Roo::CSV).to receive(:new).with(filename, file_warning: :ignore).and_call_original
29
+ expect(Roo::Spreadsheet.open(tempfile, extension: :csv)).to be_a(Roo::CSV)
30
+ end
31
+ end
32
+
14
33
  context 'for a url' do
15
34
  context 'that is csv' do
16
35
  let(:filename) { 'http://example.com/file.csv?with=params#and=anchor' }
@@ -24,33 +43,42 @@ describe Roo::Spreadsheet do
24
43
 
25
44
  context 'for a csv file' do
26
45
  let(:filename) { 'file.csv' }
27
- let(:options) { {csv_options: {col_sep: '"'}} }
46
+ let(:options) { { csv_options: { col_sep: '"' } } }
28
47
 
29
- context 'with options' do
30
- it 'passes the options through' do
48
+ context 'with csv_options' do
49
+ it 'passes the csv_options through' do
31
50
  expect(Roo::CSV).to receive(:new).with(filename, options)
32
51
  Roo::Spreadsheet.open(filename, options)
33
52
  end
34
53
  end
35
54
  end
36
55
 
37
- context 'when the file extension' do
56
+ context 'with a file extension option' do
38
57
  let(:filename) { 'file.xls' }
39
58
 
40
- context "is xls" do
41
- let(:options) { { extension: "xls" } }
59
+ context ':xlsx' do
60
+ let(:options) { { extension: :xlsx } }
61
+
62
+ it 'loads with xls extension options' do
63
+ expect(Roo::Excelx).to receive(:new).with(filename, options)
64
+ Roo::Spreadsheet.open(filename, options)
65
+ end
66
+ end
67
+
68
+ context 'xlsx' do
69
+ let(:options) { { extension: 'xlsx' } }
42
70
 
43
71
  it 'loads with xls extension options' do
44
- expect(Roo::Excel).to receive(:new).with(filename, options)
72
+ expect(Roo::Excelx).to receive(:new).with(filename, options)
45
73
  Roo::Spreadsheet.open(filename, options)
46
74
  end
47
75
  end
48
76
 
49
- context "is .xls" do
50
- let(:options) { { extension: ".xls" } }
77
+ context '.xlsx' do
78
+ let(:options) { { extension: '.xlsx' } }
51
79
 
52
80
  it 'loads with .xls extension options' do
53
- expect(Roo::Excel).to receive(:new).with(filename, options)
81
+ expect(Roo::Excelx).to receive(:new).with(filename, options)
54
82
  Roo::Spreadsheet.open(filename, options)
55
83
  end
56
84
  end