workbook 0.4.2 → 0.4.3

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.
Files changed (80) hide show
  1. data/.gitignore +2 -1
  2. data/.yardoc/checksums +22 -21
  3. data/.yardoc/object_types +0 -0
  4. data/.yardoc/objects/root.dat +0 -0
  5. data/Gemfile.lock +2 -2
  6. data/doc/RubyXL.html +1 -1
  7. data/doc/RubyXL/Cell.html +1 -1
  8. data/doc/RubyXL/Workbook.html +31 -31
  9. data/doc/Workbook.html +4 -4
  10. data/doc/Workbook/Book.html +5 -5
  11. data/doc/Workbook/Cell.html +202 -62
  12. data/doc/Workbook/Format.html +32 -32
  13. data/doc/Workbook/Modules.html +1 -1
  14. data/doc/Workbook/Modules/RawObjectsStorage.html +5 -5
  15. data/doc/Workbook/Modules/TableDiffSort.html +14 -14
  16. data/doc/Workbook/Modules/TypeParser.html +7 -7
  17. data/doc/Workbook/NilValue.html +434 -0
  18. data/doc/Workbook/Readers.html +3 -3
  19. data/doc/Workbook/Readers/CsvReader.html +6 -6
  20. data/doc/Workbook/Readers/OdsReader.html +562 -60
  21. data/doc/Workbook/Readers/TxtReader.html +2 -2
  22. data/doc/Workbook/Readers/XlsReader.html +14 -14
  23. data/doc/Workbook/Readers/XlsShared.html +67 -67
  24. data/doc/Workbook/Readers/XlsxReader.html +7 -7
  25. data/doc/Workbook/Row.html +243 -5
  26. data/doc/Workbook/Sheet.html +2 -2
  27. data/doc/Workbook/Table.html +669 -58
  28. data/doc/Workbook/Template.html +5 -5
  29. data/doc/Workbook/Writers.html +1 -1
  30. data/doc/Workbook/Writers/CsvTableWriter.html +1 -1
  31. data/doc/Workbook/Writers/HtmlWriter.html +27 -13
  32. data/doc/Workbook/Writers/XlsWriter.html +2 -2
  33. data/doc/_index.html +23 -8
  34. data/doc/class_list.html +1 -1
  35. data/doc/file.README.html +16 -12
  36. data/doc/index.html +16 -12
  37. data/doc/method_list.html +232 -72
  38. data/doc/top-level-namespace.html +1 -1
  39. data/lib/workbook/book.rb +25 -25
  40. data/lib/workbook/cell.rb +33 -33
  41. data/lib/workbook/format.rb +10 -10
  42. data/lib/workbook/modules/raw_objects_storage.rb +19 -19
  43. data/lib/workbook/modules/table_diff_sort.rb +22 -22
  44. data/lib/workbook/modules/type_parser.rb +18 -18
  45. data/lib/workbook/nil_value.rb +6 -6
  46. data/lib/workbook/readers/csv_reader.rb +8 -8
  47. data/lib/workbook/readers/ods_reader.rb +92 -46
  48. data/lib/workbook/readers/txt_reader.rb +2 -2
  49. data/lib/workbook/readers/xls_reader.rb +19 -19
  50. data/lib/workbook/readers/xls_shared.rb +70 -70
  51. data/lib/workbook/readers/xlsx_reader.rb +42 -42
  52. data/lib/workbook/row.rb +59 -29
  53. data/lib/workbook/sheet.rb +8 -8
  54. data/lib/workbook/table.rb +52 -19
  55. data/lib/workbook/template.rb +10 -10
  56. data/lib/workbook/version.rb +1 -1
  57. data/lib/workbook/writers/csv_table_writer.rb +1 -1
  58. data/lib/workbook/writers/html_writer.rb +6 -6
  59. data/lib/workbook/writers/xls_writer.rb +12 -12
  60. data/rbeautify.rb +232 -0
  61. data/test/artifacts/book_with_colspans.ods +0 -0
  62. data/test/artifacts/book_with_tabs_and_colours.ods +0 -0
  63. data/test/test_book.rb +10 -10
  64. data/test/test_cell.rb +14 -14
  65. data/test/test_format.rb +11 -11
  66. data/test/test_functional.rb +3 -3
  67. data/test/test_modules_table_diff_sort.rb +24 -24
  68. data/test/test_modules_type_parser.rb +27 -27
  69. data/test/test_readers_csv_reader.rb +11 -11
  70. data/test/test_readers_ods_reader.rb +22 -15
  71. data/test/test_readers_txt_reader.rb +13 -13
  72. data/test/test_readers_xls_reader.rb +11 -11
  73. data/test/test_readers_xlsx_reader.rb +5 -5
  74. data/test/test_row.rb +96 -26
  75. data/test/test_sheet.rb +9 -9
  76. data/test/test_table.rb +42 -26
  77. data/test/test_template.rb +3 -3
  78. data/test/test_writers_html_writer.rb +6 -4
  79. data/test/test_writers_xls_writer.rb +7 -7
  80. metadata +5 -1
data/test/test_sheet.rb CHANGED
@@ -11,19 +11,19 @@ class TestWorkbook < Test::Unit::TestCase
11
11
  assert_equal(w.count,1)
12
12
  t = Workbook::Table.new []
13
13
  w = Workbook::Sheet.new t
14
- assert_equal([t],w)
14
+ assert_equal([t],w)
15
15
  assert_equal(w.count,1)
16
16
  end
17
-
17
+
18
18
  def test_table
19
19
  w = Workbook::Sheet.new nil
20
20
  assert_equal([],w.table)
21
21
  t = Workbook::Table.new []
22
22
  w = Workbook::Sheet.new t
23
23
  assert_equal(w.table,t)
24
-
24
+
25
25
  end
26
-
26
+
27
27
  def test_book
28
28
  s = Workbook::Sheet.new
29
29
  b = s.book
@@ -31,7 +31,7 @@ class TestWorkbook < Test::Unit::TestCase
31
31
  assert_equal(s, b.sheet)
32
32
  assert_equal(s.book.sheet, b.sheet.table.sheet)
33
33
  end
34
-
34
+
35
35
  def test_clone
36
36
  w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
37
37
  s = w.sheet
@@ -41,7 +41,7 @@ class TestWorkbook < Test::Unit::TestCase
41
41
  assert_equal(3,s.table[2][:a])
42
42
  assert_equal(5,s2.table[2][:a])
43
43
  end
44
-
44
+
45
45
  def test_create_or_open_table_at
46
46
  s = Workbook::Sheet.new
47
47
  table0=s.create_or_open_table_at(0)
@@ -50,8 +50,8 @@ class TestWorkbook < Test::Unit::TestCase
50
50
  table1=s.create_or_open_table_at(1)
51
51
  assert_equal(Workbook::Table, table1.class)
52
52
  assert_equal(s, table1.sheet)
53
- table1<<Workbook::Row.new([1,2,3,4])
54
- assert_equal(false, table1 == table0)
55
-
53
+ table1<<Workbook::Row.new([1,2,3,4])
54
+ assert_equal(false, table1 == table0)
55
+
56
56
  end
57
57
  end
data/test/test_table.rb CHANGED
@@ -7,7 +7,7 @@ class TestTable< Test::Unit::TestCase
7
7
  assert_equal(t,[])
8
8
  c = Workbook::Cell.new("celllll")
9
9
  t = Workbook::Table.new [[c]]
10
-
10
+
11
11
  assert_equal([[c]],t)
12
12
  end
13
13
  def test_header
@@ -17,28 +17,28 @@ class TestTable< Test::Unit::TestCase
17
17
  assert_equal(t.header,[1])
18
18
  assert_equal(t.header.class,Workbook::Row)
19
19
  end
20
-
20
+
21
21
  def test_new_row
22
22
  t = Workbook::Table.new
23
23
  assert_equal(t.count, 0)
24
-
24
+
25
25
  r = t.new_row [1,2,3,4]
26
26
  assert_equal(r, [1,2,3,4])
27
- assert_equal(r.class, Workbook::Row)
27
+ assert_equal(r.class, Workbook::Row)
28
28
  assert_equal(1,t.count)
29
-
29
+
30
30
  r = t.new_row
31
31
  assert_equal(r.empty?, true)
32
32
  assert_equal(r.class, Workbook::Row)
33
-
33
+
34
34
  assert_equal(2, t.count)
35
35
  assert_equal(r, t.last)
36
-
36
+
37
37
  r << 2
38
38
 
39
39
  assert_equal(t.last.empty?, false)
40
40
  end
41
-
41
+
42
42
  def test_append_row
43
43
  t = Workbook::Table.new
44
44
  row = t.new_row(["a","b"])
@@ -49,23 +49,26 @@ class TestTable< Test::Unit::TestCase
49
49
  assert_equal(t, row.table)
50
50
  row = Workbook::Row.new([3,4])
51
51
  assert_equal(nil, row.table)
52
- t << row
52
+ t << row
53
53
  assert_equal(t, row.table)
54
+ t = Workbook::Table.new
55
+ t << [1,2,3,4]
56
+ assert_equal(Workbook::Row,t.first.class)
54
57
  end
55
-
58
+
56
59
  def test_sheet
57
60
  t = Workbook::Table.new
58
61
  s = t.sheet
59
62
  assert_equal(t, s.table)
60
63
  assert_equal(t.sheet, s)
61
64
  end
62
-
65
+
63
66
  def test_name
64
67
  t = Workbook::Table.new
65
68
  t.name = "test naam"
66
69
  assert_equal("test naam", t.name)
67
70
  end
68
-
71
+
69
72
  def test_delete_all
70
73
  w = Workbook::Book.new [["a","b"],[1,2],[3,4]]
71
74
  t = w.sheet.table
@@ -83,7 +86,7 @@ class TestTable< Test::Unit::TestCase
83
86
  assert_equal(3,t[2][:a])
84
87
  assert_equal(5,t2[2][:a])
85
88
  end
86
-
89
+
87
90
  def test_clone_custom_header
88
91
  w = Workbook::Book.new [[nil, nil],["a","b"],[1,2],[3,4]]
89
92
  t = w.sheet.table
@@ -94,7 +97,7 @@ class TestTable< Test::Unit::TestCase
94
97
  assert_equal(3,t[3][:a])
95
98
  assert_equal(5,t2[3][:a])
96
99
  end
97
-
100
+
98
101
  def test_spreadsheet_style_cell_addressing
99
102
  w = Workbook::Book.new [[nil, nil],["a","b"],[1,2],[3,4]]
100
103
  t = w.sheet.table
@@ -106,20 +109,33 @@ class TestTable< Test::Unit::TestCase
106
109
  assert_equal(2,t["B3"].value)
107
110
  assert_equal(3,t["A4"].value)
108
111
  assert_equal(4,t["B4"].value)
109
- # t["B4"]="asdf"
110
- # assert_equal("asdf",t["B4"].value)
111
-
112
112
  end
113
113
 
114
114
  def test_alpha_index_to_number_index
115
- w = Workbook::Book.new
116
- t = w.sheet.table
117
- assert_equal(0,t.alpha_index_to_number_index("A"))
118
- assert_equal(2,t.alpha_index_to_number_index("C"))
119
- assert_equal(25,t.alpha_index_to_number_index("Z"))
120
- assert_equal(26,t.alpha_index_to_number_index("AA"))
121
- assert_equal(27,t.alpha_index_to_number_index("AB"))
122
- assert_equal(51,t.alpha_index_to_number_index("AZ"))
123
- assert_equal(52,t.alpha_index_to_number_index("BA"))
115
+ w = Workbook::Book.new
116
+ t = w.sheet.table
117
+ assert_equal(0,t.alpha_index_to_number_index("A"))
118
+ assert_equal(2,t.alpha_index_to_number_index("C"))
119
+ assert_equal(25,t.alpha_index_to_number_index("Z"))
120
+ assert_equal(26,t.alpha_index_to_number_index("AA"))
121
+ assert_equal(27,t.alpha_index_to_number_index("AB"))
122
+ assert_equal(51,t.alpha_index_to_number_index("AZ"))
123
+ assert_equal(52,t.alpha_index_to_number_index("BA"))
124
+ end
125
+
126
+ def test_trim!
127
+ t = Workbook::Table.new
128
+ t << [1,2,3]
129
+ t << [1,2,nil,nil]
130
+ t.trim!
131
+ assert_equal("1,2,3\n1,2,\n",t.to_csv)
132
+ t = Workbook::Table.new
133
+ t << [1,2,3]
134
+ t << [nil]
135
+ t << [1,2,nil,nil]
136
+ t << [nil,nil,nil,nil]
137
+ t << [nil,nil,nil,nil]
138
+ t.trim!
139
+ assert_equal("1,2,3\n,,\n1,2,\n",t.to_csv)
124
140
  end
125
141
  end
@@ -2,14 +2,14 @@
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  class TestTemplate < Test::Unit::TestCase
5
-
5
+
6
6
  def test_initalize
7
7
  t = Workbook::Template.new
8
8
  assert_equal(true,(t.methods.include?(:add_raw) or t.methods.include?("add_raw")))
9
9
  assert_equal(true,(t.methods.include?(:has_raw_for?) or t.methods.include?("has_raw_for?")))
10
10
  assert_equal(true,(t.methods.include?(:raws) or t.methods.include?("raws")))
11
11
  end
12
-
12
+
13
13
  def test_add_raw_and_has_raw_for
14
14
  t = Workbook::Template.new
15
15
  t.add_raw "asdfsadf"
@@ -21,5 +21,5 @@ class TestTemplate < Test::Unit::TestCase
21
21
  t.add_raw "asdfsadf"
22
22
  assert_equal({String=>"asdfsadf"}, t.raws)
23
23
  end
24
-
24
+
25
25
  end
@@ -2,9 +2,11 @@
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  module Writers
5
- class TestXlsWriter < Test::Unit::TestCase
5
+ class TestHtmlWriter < Test::Unit::TestCase
6
6
  def test_to_html
7
- match = Workbook::Book.new.to_html.match(/<table><\/table>/) ? true : false
7
+ #jruby and ruby's output differ a bit... both produce valid results though
8
+ match = Workbook::Book.new.to_html.match(/<table \/>/) ? true : false #jruby
9
+ match = (Workbook::Book.new.to_html.match(/<table><\/table>/) ? true : false) if match == false #ruby
8
10
  assert_equal(true, match)
9
11
  html = Workbook::Book.new([['a','b'],[1,2],[3,4]]).to_html
10
12
  match = html.match(/<table><\/table>/) ? true : false
@@ -43,11 +45,11 @@ module Writers
43
45
  end
44
46
  def test_col_and_rowspans
45
47
  w = Workbook::Book.new
46
- w.open("test/artifacts/sheet_with_combined_cells.ods")
48
+ w.open File.join(File.dirname(__FILE__), 'artifacts/sheet_with_combined_cells.ods')
47
49
  html = w.to_html
48
50
  assert_equal(true, (html.match(/rowspan="2">15 nov 11 15 nov 11/) ? true : false) )
49
51
  assert_equal(true, (html.match(/colspan="2" rowspan="2">13 mrt 12 15 mrt 12 13 mrt 12 15 mrt 12/) ? true : false) )
50
52
  assert_equal(true, (html.match(/colspan="2">14 90589/) ? true : false) )
51
53
  end
52
54
  end
53
- end
55
+ end
@@ -5,24 +5,24 @@ module Writers
5
5
  class TestXlsWriter < Test::Unit::TestCase
6
6
  def test_to_xls
7
7
  b = Workbook::Book.new [['a','b','c'],[1,2,3],[3,2,3]]
8
- raw = Spreadsheet.open('test/artifacts/simple_sheet.xls')
8
+ raw = Spreadsheet.open File.join(File.dirname(__FILE__), 'artifacts/simple_sheet.xls')
9
9
  t = Workbook::Template.new
10
10
  t.add_raw raw
11
11
  b.template = t
12
12
  assert_equal(true, b.to_xls.is_a?(Spreadsheet::Workbook))
13
-
13
+
14
14
  assert_equal('untitled document.xls', b.write_to_xls)
15
15
  end
16
-
16
+
17
17
  def test_roundtrip
18
- b = Workbook::Book.open('test/artifacts/simple_sheet.xls')
18
+ b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/simple_sheet.xls')
19
19
  assert_equal(3.85546875,b.sheet.table.first[:a].format[:width])
20
20
  filename = b.write_to_xls
21
21
  b = Workbook::Book.open filename
22
22
  assert_equal(3.85546875,b.sheet.table.first[:a].format[:width])
23
23
  end
24
24
  def test_cloning_roundtrip
25
- b = Workbook::Book.open('test/artifacts/book_with_tabs_and_colours.xls')
25
+ b = Workbook::Book.open File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xls')
26
26
  b.sheet.table << b.sheet.table[2]
27
27
  assert_equal(90588,b.sheet.table[5][:b].value)
28
28
  assert_equal("#FFFF00",b.sheet.table[5][:c].format[:background_color])
@@ -31,13 +31,13 @@ module Writers
31
31
  assert_equal(90588,b.sheet.table[5][:b].value)
32
32
  assert_equal("#FFFF00",b.sheet.table[5][:c].format[:background_color])
33
33
  end
34
-
34
+
35
35
  def test_init_spreadsheet_template
36
36
  b = Workbook::Book.new
37
37
  b.init_spreadsheet_template
38
38
  assert_equal(Spreadsheet::Workbook,b.xls_template.class)
39
39
  end
40
-
40
+
41
41
  def test_xls_sheet
42
42
  b = Workbook::Book.new
43
43
  b.init_spreadsheet_template
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -138,6 +138,7 @@ files:
138
138
  - doc/Workbook/Modules/RawObjectsStorage.html
139
139
  - doc/Workbook/Modules/TableDiffSort.html
140
140
  - doc/Workbook/Modules/TypeParser.html
141
+ - doc/Workbook/NilValue.html
141
142
  - doc/Workbook/Readers.html
142
143
  - doc/Workbook/Readers/CsvReader.html
143
144
  - doc/Workbook/Readers/OdsReader.html
@@ -189,6 +190,8 @@ files:
189
190
  - lib/workbook/writers/csv_table_writer.rb
190
191
  - lib/workbook/writers/html_writer.rb
191
192
  - lib/workbook/writers/xls_writer.rb
193
+ - rbeautify.rb
194
+ - test/artifacts/book_with_colspans.ods
192
195
  - test/artifacts/book_with_tabs_and_colours.ods
193
196
  - test/artifacts/book_with_tabs_and_colours.xls
194
197
  - test/artifacts/book_with_tabs_and_colours.xlsx
@@ -255,6 +258,7 @@ specification_version: 3
255
258
  summary: Workbook is a datastructure to contain books of tables (an anlogy used in
256
259
  e.g. Excel)
257
260
  test_files:
261
+ - test/artifacts/book_with_colspans.ods
258
262
  - test/artifacts/book_with_tabs_and_colours.ods
259
263
  - test/artifacts/book_with_tabs_and_colours.xls
260
264
  - test/artifacts/book_with_tabs_and_colours.xlsx