workbook 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +21 -0
- data/.gitignore +4 -1
- data/.ruby-version +1 -1
- data/.travis.yml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -2
- data/README.md +9 -7
- data/Rakefile +6 -6
- data/lib/workbook/book.rb +73 -62
- data/lib/workbook/cell.rb +58 -13
- data/lib/workbook/column.rb +31 -28
- data/lib/workbook/format.rb +23 -24
- data/lib/workbook/generatetypes.rb +4 -4
- data/lib/workbook/modules/cache.rb +6 -7
- data/lib/workbook/modules/cell.rb +77 -100
- data/lib/workbook/modules/diff_sort.rb +92 -83
- data/lib/workbook/modules/raw_objects_storage.rb +6 -8
- data/lib/workbook/modules/type_parser.rb +30 -22
- data/lib/workbook/nil_value.rb +4 -9
- data/lib/workbook/readers/csv_reader.rb +7 -10
- data/lib/workbook/readers/ods_reader.rb +48 -50
- data/lib/workbook/readers/txt_reader.rb +6 -8
- data/lib/workbook/readers/xls_reader.rb +21 -33
- data/lib/workbook/readers/xls_shared.rb +106 -117
- data/lib/workbook/readers/xlsx_reader.rb +45 -46
- data/lib/workbook/row.rb +99 -84
- data/lib/workbook/sheet.rb +47 -38
- data/lib/workbook/table.rb +96 -72
- data/lib/workbook/template.rb +12 -15
- data/lib/workbook/types/false.rb +0 -1
- data/lib/workbook/types/nil.rb +0 -1
- data/lib/workbook/types/nil_class.rb +1 -1
- data/lib/workbook/types/numeric.rb +1 -1
- data/lib/workbook/types/string.rb +1 -1
- data/lib/workbook/types/time.rb +1 -1
- data/lib/workbook/types/true.rb +0 -1
- data/lib/workbook/types/true_class.rb +1 -1
- data/lib/workbook/version.rb +2 -3
- data/lib/workbook/writers/csv_table_writer.rb +10 -13
- data/lib/workbook/writers/html_writer.rb +34 -38
- data/lib/workbook/writers/json_table_writer.rb +8 -11
- data/lib/workbook/writers/xls_writer.rb +30 -36
- data/lib/workbook/writers/xlsx_writer.rb +45 -29
- data/lib/workbook.rb +16 -15
- data/test/helper.rb +6 -5
- data/test/test_book.rb +41 -38
- data/test/test_column.rb +26 -24
- data/test/test_format.rb +51 -55
- data/test/test_functional.rb +7 -8
- data/test/test_modules_cache.rb +18 -17
- data/test/test_modules_cell.rb +47 -46
- data/test/test_modules_table_diff_sort.rb +55 -64
- data/test/test_modules_type_parser.rb +61 -31
- data/test/test_readers_csv_reader.rb +48 -42
- data/test/test_readers_ods_reader.rb +28 -31
- data/test/test_readers_txt_reader.rb +21 -23
- data/test/test_readers_xls_reader.rb +20 -23
- data/test/test_readers_xls_shared.rb +2 -3
- data/test/test_readers_xlsx_reader.rb +44 -37
- data/test/test_row.rb +105 -109
- data/test/test_sheet.rb +41 -35
- data/test/test_table.rb +82 -60
- data/test/test_template.rb +16 -15
- data/test/test_types_date.rb +4 -6
- data/test/test_writers_csv_writer.rb +24 -0
- data/test/test_writers_html_writer.rb +42 -41
- data/test/test_writers_json_writer.rb +9 -9
- data/test/test_writers_xls_writer.rb +50 -35
- data/test/test_writers_xlsx_writer.rb +62 -34
- data/workbook.gemspec +26 -27
- metadata +92 -27
data/test/test_row.rb
CHANGED
@@ -1,33 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), 'helper')
|
3
|
+
require File.join(File.dirname(__FILE__), "helper")
|
5
4
|
|
6
5
|
class TestRow < Minitest::Test
|
7
|
-
|
8
|
-
|
9
6
|
def test_init
|
10
7
|
t = Workbook::Table.new
|
11
|
-
r = Workbook::Row.new([1,2,3],t)
|
12
|
-
|
13
|
-
c2 = Workbook::Cell.new(2)
|
14
|
-
c3 = Workbook::Cell.new(3)
|
15
|
-
assert_equal([c1,c2,c3].collect{|c| c.value},r.collect{|c| c.value})
|
8
|
+
r = Workbook::Row.new([1, 2, 3], t)
|
9
|
+
assert_equal([1, 2, 3], r.collect { |c| c.value })
|
16
10
|
|
17
|
-
#t = Workbook::Table.new
|
11
|
+
# t = Workbook::Table.new
|
18
12
|
c1 = Workbook::Cell.new(1)
|
19
13
|
c2 = Workbook::Cell.new(2)
|
20
14
|
c3 = Workbook::Cell.new(3)
|
21
15
|
|
22
|
-
r = Workbook::Row.new([c1,c2,c3])
|
23
|
-
|
24
|
-
assert_equal([c1,c2,c3],r)
|
16
|
+
r = Workbook::Row.new([c1, c2, c3])
|
25
17
|
|
18
|
+
assert_equal([c1, c2, c3], r.cells)
|
19
|
+
assert_equal(Workbook::Row, r.class)
|
26
20
|
end
|
27
21
|
|
28
22
|
def test_table=
|
29
23
|
r = Workbook::Row.new
|
30
|
-
assert_raises(ArgumentError,
|
24
|
+
assert_raises(ArgumentError, "table should be a Workbook::Table (you passed a String)") { r.table = "asdf" }
|
31
25
|
r.table = nil
|
32
26
|
assert_nil(r.table)
|
33
27
|
r = Workbook::Row.new
|
@@ -74,9 +68,9 @@ class TestRow < Minitest::Test
|
|
74
68
|
r1 = Workbook::Row.new
|
75
69
|
r1.table = t
|
76
70
|
assert_equal(true, r1.no_values?)
|
77
|
-
r1 << Workbook::Cell.new(
|
71
|
+
r1 << Workbook::Cell.new("abcd")
|
78
72
|
assert_equal(false, r1.no_values?)
|
79
|
-
r2 = Workbook::Row.new [nil,
|
73
|
+
r2 = Workbook::Row.new [nil, "", nil, "", ""]
|
80
74
|
r2.table = t
|
81
75
|
assert_equal(true, r2.no_values?)
|
82
76
|
end
|
@@ -86,39 +80,41 @@ class TestRow < Minitest::Test
|
|
86
80
|
assert_equal([:test, :asdfasd, :asdf_asdf, :asdf2], r1.to_symbols)
|
87
81
|
r1 = Workbook::Row.new ["inït", "è-éë"]
|
88
82
|
assert_equal([:init, :eee], r1.to_symbols)
|
89
|
-
|
90
83
|
end
|
91
84
|
|
92
85
|
def test_to_hash
|
93
86
|
r1 = Workbook::Row.new ["test", "asdf-asd", "asdf - asdf", "asdf2"]
|
94
|
-
assert_raises(NoMethodError,
|
87
|
+
assert_raises(NoMethodError, "undefined method `header' for nil:NilClass") { r1.to_hash }
|
95
88
|
|
96
89
|
t = Workbook::Table.new
|
97
|
-
r1 = Workbook::Row.new
|
90
|
+
r1 = Workbook::Row.new ["test", "asdf-asd"]
|
98
91
|
r1.table = t
|
99
|
-
expected = {:
|
92
|
+
expected = {test: Workbook::Cell.new("test"), asdfasd: Workbook::Cell.new("asdf-asd")}
|
100
93
|
assert_equal(expected, r1.to_hash)
|
101
94
|
date = DateTime.now
|
102
|
-
r2 = Workbook::Row.new
|
95
|
+
r2 = Workbook::Row.new [2, date]
|
103
96
|
r2.table = t
|
104
|
-
expected = {:
|
97
|
+
expected = {test: Workbook::Cell.new(2), asdfasd: Workbook::Cell.new(date)}
|
105
98
|
assert_equal(expected, r2.to_hash)
|
106
99
|
assert_equal(date, r2[:asdfasd].value)
|
107
100
|
assert_equal(date, r2[1].value)
|
108
101
|
end
|
109
102
|
|
110
|
-
|
111
103
|
def test_to_hash_with_values
|
112
104
|
t = Workbook::Table.new
|
113
|
-
r1 = Workbook::Row.new
|
105
|
+
r1 = Workbook::Row.new ["test", "asdf-asd"]
|
114
106
|
r1.table = t
|
115
|
-
expected = {:
|
107
|
+
expected = {test: "test", asdfasd: "asdf-asd"}
|
116
108
|
assert_equal(expected, r1.to_hash_with_values)
|
117
109
|
date = DateTime.now
|
118
|
-
r2 = Workbook::Row.new
|
110
|
+
r2 = Workbook::Row.new [2, date]
|
119
111
|
r2.table = t
|
120
|
-
expected = {:
|
112
|
+
expected = {test: 2, asdfasd: date}
|
121
113
|
assert_equal(expected, r2.to_hash_with_values)
|
114
|
+
r3 = Workbook::Row.new [4]
|
115
|
+
r3.table = t
|
116
|
+
expected = {test: 4, asdfasd: nil}
|
117
|
+
assert_equal(expected, r3.to_hash_with_values)
|
122
118
|
end
|
123
119
|
|
124
120
|
def test_to_hash_cache
|
@@ -137,47 +133,46 @@ class TestRow < Minitest::Test
|
|
137
133
|
end
|
138
134
|
|
139
135
|
def test_compare
|
140
|
-
r1 = Workbook::Row.new
|
141
|
-
r2 = Workbook::Row.new
|
142
|
-
assert_equal(-1,r1<=>r2)
|
143
|
-
r1 = Workbook::Row.new
|
144
|
-
r2 = Workbook::Row.new
|
145
|
-
assert_equal(-1,r1<=>r2)
|
146
|
-
r1 = Workbook::Row.new
|
147
|
-
r2 = Workbook::Row.new
|
148
|
-
assert_equal(1,r1<=>r2)
|
149
|
-
r1 = Workbook::Row.new
|
150
|
-
r2 = Workbook::Row.new
|
151
|
-
assert_equal(-1,r1<=>r2)
|
152
|
-
r1 = Workbook::Row.new
|
153
|
-
r2 = Workbook::Row.new
|
154
|
-
assert_equal(1,r1<=>r2)
|
155
|
-
r1 = Workbook::Row.new
|
156
|
-
r2 = Workbook::Row.new
|
157
|
-
assert_equal(-1,r1<=>r2)
|
158
|
-
|
136
|
+
r1 = Workbook::Row.new ["test", "asdf-asd"]
|
137
|
+
r2 = Workbook::Row.new [nil, "asdf-asd"]
|
138
|
+
assert_equal(-1, r1 <=> r2)
|
139
|
+
r1 = Workbook::Row.new [1, "asdf-asd"]
|
140
|
+
r2 = Workbook::Row.new ["test", "asdf-asd"]
|
141
|
+
assert_equal(-1, r1 <=> r2)
|
142
|
+
r1 = Workbook::Row.new [nil, "asdf-asd"]
|
143
|
+
r2 = Workbook::Row.new [Time.now, "asdf-asd"]
|
144
|
+
assert_equal(1, r1 <=> r2)
|
145
|
+
r1 = Workbook::Row.new [2, 3]
|
146
|
+
r2 = Workbook::Row.new [2, nil]
|
147
|
+
assert_equal(-1, r1 <=> r2)
|
148
|
+
r1 = Workbook::Row.new [3, 0]
|
149
|
+
r2 = Workbook::Row.new [2, 100000]
|
150
|
+
assert_equal(1, r1 <=> r2)
|
151
|
+
r1 = Workbook::Row.new [-10, 3]
|
152
|
+
r2 = Workbook::Row.new [nil, 5]
|
153
|
+
assert_equal(-1, r1 <=> r2)
|
159
154
|
end
|
160
155
|
|
161
156
|
def test_find_cells_by_background_color
|
162
|
-
r = Workbook::Row.new
|
163
|
-
assert_equal([],r.find_cells_by_background_color)
|
157
|
+
r = Workbook::Row.new ["test", "asdf-asd"]
|
158
|
+
assert_equal([], r.find_cells_by_background_color)
|
164
159
|
f = Workbook::Format.new
|
165
|
-
f[:background_color]=
|
160
|
+
f[:background_color] = "#ff00ff"
|
166
161
|
r.first.format = f
|
167
|
-
assert_equal([:test],r.find_cells_by_background_color)
|
168
|
-
assert_equal([],r.find_cells_by_background_color(
|
162
|
+
assert_equal([:test], r.find_cells_by_background_color)
|
163
|
+
assert_equal([], r.find_cells_by_background_color("#ff0000"))
|
169
164
|
end
|
170
165
|
|
171
166
|
def test_to_s
|
172
167
|
r1 = Workbook::Row.new ["test", "asdf-asd"]
|
173
|
-
assert_equal("test,asdf-asd\n",r1.to_csv)
|
168
|
+
assert_equal("test,asdf-asd\n", r1.to_csv)
|
174
169
|
end
|
175
170
|
|
176
171
|
def test_clone
|
177
172
|
b = Workbook::Book.new
|
178
173
|
table = b.sheet.table
|
179
|
-
table << Workbook::Row.new(["a","b"])
|
180
|
-
row = Workbook::Row.new(["1","2"])
|
174
|
+
table << Workbook::Row.new(["a", "b"])
|
175
|
+
row = Workbook::Row.new(["1", "2"])
|
181
176
|
table << row
|
182
177
|
table << row
|
183
178
|
row[1] = Workbook::Cell.new(3)
|
@@ -189,61 +184,61 @@ class TestRow < Minitest::Test
|
|
189
184
|
def test_clone_has_no_table
|
190
185
|
b = Workbook::Book.new
|
191
186
|
table = b.sheet.table
|
192
|
-
table << Workbook::Row.new(["a","b"])
|
193
|
-
table << Workbook::Row.new([1,2])
|
187
|
+
table << Workbook::Row.new(["a", "b"])
|
188
|
+
table << Workbook::Row.new([1, 2])
|
194
189
|
row = table[1].clone
|
195
190
|
assert_nil(row[:a])
|
196
191
|
assert_nil(row[:b])
|
197
|
-
assert_equal(1,row[0].value)
|
198
|
-
assert_equal(2,row[1].value)
|
192
|
+
assert_equal(1, row[0].value)
|
193
|
+
assert_equal(2, row[1].value)
|
199
194
|
end
|
200
195
|
|
201
196
|
def test_push
|
202
197
|
b = Workbook::Book.new
|
203
198
|
table = b.sheet.table
|
204
|
-
table << Workbook::Row.new(["a","b"])
|
205
|
-
table << Workbook::Row.new([1,2])
|
206
|
-
assert_equal(1,table[1][:a].value)
|
207
|
-
assert_equal(2,table[1][:b].value)
|
199
|
+
table << Workbook::Row.new(["a", "b"])
|
200
|
+
table << Workbook::Row.new([1, 2])
|
201
|
+
assert_equal(1, table[1][:a].value)
|
202
|
+
assert_equal(2, table[1][:b].value)
|
208
203
|
b = Workbook::Book.new
|
209
204
|
table = b.sheet.table
|
210
|
-
table.push Workbook::Row.new(["a","b"])
|
211
|
-
table.push Workbook::Row.new([1,2])
|
212
|
-
assert_equal(1,table[1][:a].value)
|
213
|
-
assert_equal(2,table[1][:b].value)
|
205
|
+
table.push Workbook::Row.new(["a", "b"])
|
206
|
+
table.push Workbook::Row.new([1, 2])
|
207
|
+
assert_equal(1, table[1][:a].value)
|
208
|
+
assert_equal(2, table[1][:b].value)
|
214
209
|
end
|
215
210
|
|
216
211
|
def test_assign
|
217
212
|
b = Workbook::Book.new
|
218
213
|
table = b.sheet.table
|
219
|
-
table.push Workbook::Row.new(["a","b"])
|
220
|
-
table[1] = Workbook::Row.new([1,2])
|
221
|
-
assert_equal(1,table[1][:a].value)
|
222
|
-
assert_equal(2,table[1][:b].value)
|
214
|
+
table.push Workbook::Row.new(["a", "b"])
|
215
|
+
table[1] = Workbook::Row.new([1, 2])
|
216
|
+
assert_equal(1, table[1][:a].value)
|
217
|
+
assert_equal(2, table[1][:b].value)
|
223
218
|
|
224
219
|
b = Workbook::Book.new
|
225
220
|
table = b.sheet.table
|
226
|
-
table.push Workbook::Row.new(["a","b"])
|
227
|
-
table[1] = [1,2]
|
228
|
-
assert_equal(1,table[1][:a].value)
|
229
|
-
assert_equal(2,table[1][:b].value)
|
221
|
+
table.push Workbook::Row.new(["a", "b"])
|
222
|
+
table[1] = [1, 2]
|
223
|
+
assert_equal(1, table[1][:a].value)
|
224
|
+
assert_equal(2, table[1][:b].value)
|
230
225
|
end
|
231
226
|
|
232
227
|
def test_preservation_of_format_on_assign
|
233
|
-
row = Workbook::Row.new([1,2])
|
228
|
+
row = Workbook::Row.new([1, 2])
|
234
229
|
cellformat = row.first.format
|
235
|
-
cellformat["background"]="#f00"
|
230
|
+
cellformat["background"] = "#f00"
|
236
231
|
row[0] = 3
|
237
|
-
assert_equal(3,row[0].value)
|
238
|
-
assert_equal("#f00",row[0].format["background"])
|
232
|
+
assert_equal(3, row[0].value)
|
233
|
+
assert_equal("#f00", row[0].format["background"])
|
239
234
|
end
|
240
235
|
|
241
236
|
def test_find_by_string
|
242
237
|
b = Workbook::Book.new
|
243
238
|
table = b.sheet.table
|
244
|
-
table << Workbook::Row.new(["a","b"])
|
245
|
-
row = Workbook::Row.new([],table)
|
246
|
-
row[1]= 12
|
239
|
+
table << Workbook::Row.new(["a", "b"])
|
240
|
+
row = Workbook::Row.new([], table)
|
241
|
+
row[1] = 12
|
247
242
|
assert_equal(12, table.last["b"])
|
248
243
|
assert_nil(table.last["a"])
|
249
244
|
end
|
@@ -251,9 +246,9 @@ class TestRow < Minitest::Test
|
|
251
246
|
def test_find_by_column_string
|
252
247
|
b = Workbook::Book.new
|
253
248
|
table = b.sheet.table
|
254
|
-
table << Workbook::Row.new(["b","a"])
|
255
|
-
row = Workbook::Row.new([],table)
|
256
|
-
row[1]= 12
|
249
|
+
table << Workbook::Row.new(["b", "a"])
|
250
|
+
row = Workbook::Row.new([], table)
|
251
|
+
row[1] = 12
|
257
252
|
assert_equal(12, table.last["B"])
|
258
253
|
assert_nil(table.last["A"])
|
259
254
|
end
|
@@ -261,15 +256,15 @@ class TestRow < Minitest::Test
|
|
261
256
|
def test_row_hash_index_string_assignment
|
262
257
|
b = Workbook::Book.new
|
263
258
|
table = b.sheet.table
|
264
|
-
table << Workbook::Row.new(["a","b","d"])
|
265
|
-
row = Workbook::Row.new([],table)
|
266
|
-
row[1]= 12
|
259
|
+
table << Workbook::Row.new(["a", "b", "d"])
|
260
|
+
row = Workbook::Row.new([], table)
|
261
|
+
row[1] = 12
|
267
262
|
assert_equal(12, table.last.last.value)
|
268
|
-
row[:b]= 15
|
263
|
+
row[:b] = 15
|
269
264
|
assert_equal(15, table.last.last.value)
|
270
|
-
row["b"]= 18
|
265
|
+
row["b"] = 18
|
271
266
|
assert_equal(18, table.last.last.value)
|
272
|
-
row["C"]= 2
|
267
|
+
row["C"] = 2
|
273
268
|
assert_equal(2, table.last[2].value)
|
274
269
|
end
|
275
270
|
|
@@ -340,7 +335,6 @@ class TestRow < Minitest::Test
|
|
340
335
|
d = a.trim
|
341
336
|
assert_equal(b, a)
|
342
337
|
assert_equal(c, d)
|
343
|
-
|
344
338
|
end
|
345
339
|
|
346
340
|
def test_add
|
@@ -350,40 +344,42 @@ class TestRow < Minitest::Test
|
|
350
344
|
a << "asdf"
|
351
345
|
a << 2.2
|
352
346
|
a.push(5)
|
353
|
-
assert_equal(1,a[0].value)
|
354
|
-
assert_equal(2,a[1].value)
|
355
|
-
assert_equal("asdf",a[2].value)
|
356
|
-
assert_equal(2.2,a[3].value)
|
357
|
-
assert_equal(5,a[4].value)
|
347
|
+
assert_equal(1, a[0].value)
|
348
|
+
assert_equal(2, a[1].value)
|
349
|
+
assert_equal("asdf", a[2].value)
|
350
|
+
assert_equal(2.2, a[3].value)
|
351
|
+
assert_equal(5, a[4].value)
|
358
352
|
end
|
359
353
|
|
360
354
|
def test_plus
|
361
|
-
header = Workbook::Row.new([:a
|
355
|
+
header = Workbook::Row.new([:a, :b])
|
362
356
|
a = Workbook::Row.new
|
363
357
|
table = Workbook::Table.new
|
364
358
|
table << header
|
365
359
|
table << a
|
366
360
|
assert_equal(table, a.table)
|
367
|
-
assert_equal(Workbook::Row, (a + [1,1]).class
|
368
|
-
assert_equal([1,1],(a + [1,1]).to_a
|
369
|
-
assert_equal(Workbook::Cell,(a + [1,1])[0].class
|
370
|
-
a += [1,1]
|
371
|
-
assert_equal([1,1],a.to_a
|
372
|
-
assert_equal(Workbook::Row, a.class
|
361
|
+
assert_equal(Workbook::Row, (a + [1, 1]).class)
|
362
|
+
assert_equal([1, 1], (a + [1, 1]).to_a)
|
363
|
+
assert_equal(Workbook::Cell, (a + [1, 1])[0].class)
|
364
|
+
a += [1, 1]
|
365
|
+
assert_equal([1, 1], a.to_a)
|
366
|
+
assert_equal(Workbook::Row, a.class)
|
373
367
|
assert_nil(a.table)
|
374
|
-
assert_equal(Workbook::Cell,a[0].class)
|
368
|
+
assert_equal(Workbook::Cell, a[0].class)
|
375
369
|
end
|
376
370
|
|
377
371
|
def test_concat
|
378
|
-
header = Workbook::Row.new([:a
|
372
|
+
header = Workbook::Row.new([:a, :b])
|
379
373
|
a = Workbook::Row.new
|
380
374
|
table = Workbook::Table.new
|
381
375
|
table << header
|
382
376
|
table << a
|
383
|
-
|
384
|
-
|
385
|
-
|
377
|
+
|
378
|
+
a.concat [1, 1]
|
379
|
+
|
380
|
+
assert_equal([1, 1], a.to_a)
|
381
|
+
assert_equal(Workbook::Row, a.class)
|
386
382
|
assert_equal(table, a.table)
|
387
|
-
assert_equal(Workbook::Cell,a[0].class)
|
383
|
+
assert_equal(Workbook::Cell, a[0].class)
|
388
384
|
end
|
389
385
|
end
|
data/test/test_sheet.rb
CHANGED
@@ -1,38 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), 'helper')
|
3
|
+
require File.join(File.dirname(__FILE__), "helper")
|
5
4
|
|
6
5
|
class TestWorkbook < Minitest::Test
|
7
6
|
def test_init
|
8
|
-
|
9
|
-
assert_equal(
|
10
|
-
assert_equal(
|
11
|
-
|
12
|
-
|
13
|
-
assert_equal(
|
7
|
+
s = Workbook::Sheet.new nil
|
8
|
+
assert_equal(Workbook::Sheet, s.class)
|
9
|
+
assert_equal(s.count, 1)
|
10
|
+
|
11
|
+
s = Workbook::Sheet.new
|
12
|
+
assert_equal(Workbook::Sheet, s.class)
|
13
|
+
assert_equal(s.count, 1)
|
14
|
+
|
14
15
|
t = Workbook::Table.new []
|
15
|
-
|
16
|
-
assert_equal(
|
17
|
-
assert_equal(
|
16
|
+
s = Workbook::Sheet.new t
|
17
|
+
assert_equal(Workbook::Sheet, s.class)
|
18
|
+
assert_equal(t, s.table)
|
19
|
+
assert_equal(s.count, 1)
|
18
20
|
end
|
19
21
|
|
20
22
|
def test_table
|
21
23
|
w = Workbook::Sheet.new nil
|
22
|
-
assert_equal([],w.table)
|
24
|
+
assert_equal(Workbook::Table.new([]), w.table)
|
23
25
|
t = Workbook::Table.new []
|
24
26
|
w = Workbook::Sheet.new t
|
25
|
-
assert_equal(w.table,t)
|
27
|
+
assert_equal(w.table, t)
|
26
28
|
end
|
27
29
|
|
28
30
|
def test_table_assignment
|
29
31
|
t = Workbook::Table.new []
|
30
32
|
s = Workbook::Sheet.new t
|
31
|
-
assert_equal(s.table,t)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
assert_equal(
|
33
|
+
assert_equal(s.table, t)
|
34
|
+
|
35
|
+
data = [["a", "b"], [1, 2]]
|
36
|
+
s.table = data
|
37
|
+
assert_equal("a", s.table["A1"].value)
|
38
|
+
assert_equal(2, s.table["B2"].value)
|
36
39
|
end
|
37
40
|
|
38
41
|
def test_book
|
@@ -44,45 +47,48 @@ class TestWorkbook < Minitest::Test
|
|
44
47
|
end
|
45
48
|
|
46
49
|
def test_clone
|
47
|
-
w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
|
50
|
+
w = Workbook::Book.new [["a", "b"], [1, 2], [3, 4]]
|
48
51
|
s = w.sheet
|
49
|
-
|
52
|
+
|
53
|
+
assert_equal(3, s.table[2][:a])
|
54
|
+
|
50
55
|
s2 = s.clone
|
56
|
+
|
51
57
|
s2.table[2][:a] = 5
|
52
|
-
assert_equal(3,s.table[2][:a])
|
53
|
-
assert_equal(5,s2.table[2][:a])
|
58
|
+
assert_equal(3, s.table[2][:a])
|
59
|
+
assert_equal(5, s2.table[2][:a])
|
54
60
|
end
|
55
61
|
|
56
62
|
def test_create_or_open_table_at
|
57
63
|
s = Workbook::Sheet.new
|
58
|
-
table0=s.create_or_open_table_at(0)
|
64
|
+
table0 = s.create_or_open_table_at(0)
|
59
65
|
assert_equal(Workbook::Table, table0.class)
|
60
66
|
assert_equal(s, table0.sheet)
|
61
|
-
table1=s.create_or_open_table_at(1)
|
67
|
+
table1 = s.create_or_open_table_at(1)
|
62
68
|
assert_equal(Workbook::Table, table1.class)
|
63
69
|
assert_equal(s, table1.sheet)
|
64
|
-
table1<<Workbook::Row.new([1,2,3,4])
|
70
|
+
table1 << Workbook::Row.new([1, 2, 3, 4])
|
65
71
|
assert_equal(false, table1 == table0)
|
66
72
|
end
|
73
|
+
|
67
74
|
def test_profile_speed
|
68
|
-
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]]
|
69
|
-
require
|
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"
|
70
77
|
RubyProf.start
|
71
78
|
w.sheet.table.each do |row|
|
72
|
-
|
79
|
+
row[:a].value
|
73
80
|
end
|
74
81
|
result = RubyProf.stop
|
75
82
|
printer = RubyProf::MultiPrinter.new(result)
|
76
|
-
printer.print(:
|
77
|
-
|
83
|
+
printer.print(path: ".", profile: "profile")
|
78
84
|
end
|
85
|
+
|
79
86
|
def test_name
|
80
|
-
b = Workbook::Book.new [["a","b"],[1,2]]
|
81
|
-
b.push Workbook::Sheet.new([["a","b"],[2,2]])
|
82
|
-
b.push Workbook::Sheet.new([["a","b"],[3,2]])
|
87
|
+
b = Workbook::Book.new [["a", "b"], [1, 2]]
|
88
|
+
b.push Workbook::Sheet.new([["a", "b"], [2, 2]])
|
89
|
+
b.push Workbook::Sheet.new([["a", "b"], [3, 2]])
|
83
90
|
|
84
91
|
# puts b.index b.last
|
85
|
-
assert_equal(["Sheet 1", "Sheet 2", "Sheet 3"], b.collect{|a| a.name})
|
92
|
+
assert_equal(["Sheet 1", "Sheet 2", "Sheet 3"], b.collect { |a| a.name })
|
86
93
|
end
|
87
|
-
|
88
94
|
end
|