workbook 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +21 -0
  3. data/.gitignore +4 -1
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +4 -4
  6. data/CHANGELOG.md +7 -0
  7. data/Gemfile +2 -2
  8. data/README.md +9 -7
  9. data/Rakefile +6 -6
  10. data/lib/workbook/book.rb +73 -62
  11. data/lib/workbook/cell.rb +58 -13
  12. data/lib/workbook/column.rb +31 -28
  13. data/lib/workbook/format.rb +23 -24
  14. data/lib/workbook/generatetypes.rb +4 -4
  15. data/lib/workbook/modules/cache.rb +6 -7
  16. data/lib/workbook/modules/cell.rb +77 -100
  17. data/lib/workbook/modules/diff_sort.rb +92 -83
  18. data/lib/workbook/modules/raw_objects_storage.rb +6 -8
  19. data/lib/workbook/modules/type_parser.rb +30 -22
  20. data/lib/workbook/nil_value.rb +4 -9
  21. data/lib/workbook/readers/csv_reader.rb +7 -10
  22. data/lib/workbook/readers/ods_reader.rb +48 -50
  23. data/lib/workbook/readers/txt_reader.rb +6 -8
  24. data/lib/workbook/readers/xls_reader.rb +21 -33
  25. data/lib/workbook/readers/xls_shared.rb +106 -117
  26. data/lib/workbook/readers/xlsx_reader.rb +45 -46
  27. data/lib/workbook/row.rb +99 -84
  28. data/lib/workbook/sheet.rb +47 -38
  29. data/lib/workbook/table.rb +96 -72
  30. data/lib/workbook/template.rb +12 -15
  31. data/lib/workbook/types/false.rb +0 -1
  32. data/lib/workbook/types/nil.rb +0 -1
  33. data/lib/workbook/types/nil_class.rb +1 -1
  34. data/lib/workbook/types/numeric.rb +1 -1
  35. data/lib/workbook/types/string.rb +1 -1
  36. data/lib/workbook/types/time.rb +1 -1
  37. data/lib/workbook/types/true.rb +0 -1
  38. data/lib/workbook/types/true_class.rb +1 -1
  39. data/lib/workbook/version.rb +2 -3
  40. data/lib/workbook/writers/csv_table_writer.rb +10 -13
  41. data/lib/workbook/writers/html_writer.rb +34 -38
  42. data/lib/workbook/writers/json_table_writer.rb +8 -11
  43. data/lib/workbook/writers/xls_writer.rb +30 -36
  44. data/lib/workbook/writers/xlsx_writer.rb +45 -29
  45. data/lib/workbook.rb +16 -15
  46. data/test/helper.rb +6 -5
  47. data/test/test_book.rb +41 -38
  48. data/test/test_column.rb +26 -24
  49. data/test/test_format.rb +51 -55
  50. data/test/test_functional.rb +7 -8
  51. data/test/test_modules_cache.rb +18 -17
  52. data/test/test_modules_cell.rb +47 -46
  53. data/test/test_modules_table_diff_sort.rb +55 -64
  54. data/test/test_modules_type_parser.rb +61 -31
  55. data/test/test_readers_csv_reader.rb +48 -42
  56. data/test/test_readers_ods_reader.rb +28 -31
  57. data/test/test_readers_txt_reader.rb +21 -23
  58. data/test/test_readers_xls_reader.rb +20 -23
  59. data/test/test_readers_xls_shared.rb +2 -3
  60. data/test/test_readers_xlsx_reader.rb +44 -37
  61. data/test/test_row.rb +105 -109
  62. data/test/test_sheet.rb +41 -35
  63. data/test/test_table.rb +82 -60
  64. data/test/test_template.rb +16 -15
  65. data/test/test_types_date.rb +4 -6
  66. data/test/test_writers_csv_writer.rb +24 -0
  67. data/test/test_writers_html_writer.rb +42 -41
  68. data/test/test_writers_json_writer.rb +9 -9
  69. data/test/test_writers_xls_writer.rb +50 -35
  70. data/test/test_writers_xlsx_writer.rb +62 -34
  71. data/workbook.gemspec +26 -27
  72. metadata +92 -27
data/test/test_book.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
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_sheets
@@ -13,32 +12,36 @@ class TestWorkbook < Minitest::Test
13
12
  def test_push
14
13
  w = Workbook::Book.new nil
15
14
  assert_equal(0, w.count)
16
- assert_equal([],w)
15
+ assert_equal(Workbook::Book, w.class)
16
+
17
17
  w = Workbook::Book.new
18
18
  w.push
19
- assert_equal(w.first.class,Workbook::Sheet)
19
+ assert_equal(w.first.class, Workbook::Sheet)
20
+
20
21
  w.push
21
- assert_equal(w,w.last.book)
22
+ assert_equal(w, w.last.book)
22
23
  assert_equal(2, w.count)
23
- s = Workbook::Sheet.new
24
+
25
+ s = Workbook::Sheet.new([[1, 2], [3, 4]])
24
26
  w.push s
25
- assert_equal(w,w.last.book)
27
+ assert_equal(w, w.last.book)
28
+
29
+ assert_equal(w.last, s)
26
30
 
27
- assert_equal(w.last,s)
28
31
  w = Workbook::Book.new
29
- assert_equal(w.sheet.table.class,Workbook::Table)
32
+ assert_equal(w.sheet.table.class, Workbook::Table)
30
33
  end
31
34
 
32
35
  def test_sheet
33
36
  w = Workbook::Book.new nil
34
37
  s = Workbook::Sheet.new [Workbook::Row.new(Workbook::Table.new)]
35
- assert_equal(w.sheet.class,Workbook::Sheet)
38
+ assert_equal(w.sheet.class, Workbook::Sheet)
36
39
  refute_equal(w.sheet, s)
37
40
  w = Workbook::Book.new s
38
41
  assert_equal(w.sheet, s)
39
42
  w = Workbook::Book.new
40
43
  s = w.sheet
41
- assert_equal([[]], s)
44
+ assert_equal(Workbook::Sheet, s.class)
42
45
  end
43
46
 
44
47
  def test_template
@@ -48,30 +51,30 @@ class TestWorkbook < Minitest::Test
48
51
  raw = Workbook::Template.new
49
52
  b.template = raw
50
53
 
51
- assert_equal(raw,b.template)
54
+ assert_equal(raw, b.template)
52
55
  end
53
56
 
54
57
  def test_file_extension
55
58
  b = Workbook::Book.new
56
- assert_equal("aaa",b.file_extension("aaa.aaa"))
59
+ assert_equal("aaa", b.file_extension("aaa.aaa"))
57
60
  b = Workbook::Book.new
58
- assert_equal("xlsx",b.file_extension(File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xlsx')))
61
+ assert_equal("xlsx", b.file_extension(File.join(File.dirname(__FILE__), "artifacts/book_with_tabs_and_colours.xlsx")))
59
62
  b = Workbook::Book.new
60
- assert_equal("xlsx",b.file_extension(File.new(File.join(File.dirname(__FILE__), 'artifacts/book_with_tabs_and_colours.xlsx'))))
63
+ assert_equal("xlsx", b.file_extension(File.new(File.join(File.dirname(__FILE__), "artifacts/book_with_tabs_and_colours.xlsx"))))
61
64
  end
62
65
 
63
66
  def test_parent_child
64
- b = Workbook::Book.new [[1,2,3],[1,2,3]]
67
+ b = Workbook::Book.new [[1, 2, 3], [1, 2, 3]]
65
68
  assert_equal(Workbook::Sheet, b.first.class)
66
- assert_equal(b,b.first.book)
69
+ assert_equal(b, b.first.book)
67
70
  assert_equal(Workbook::Table, b.first.table.class)
68
- assert_equal(b,b.first.table.sheet.book)
71
+ assert_equal(b, b.first.table.sheet.book)
69
72
  assert_equal(Workbook::Row, b.first.table.header.class)
70
- assert_equal(b,b.first.table.header.table.sheet.book)
73
+ assert_equal(b, b.first.table.header.table.sheet.book)
71
74
  end
72
75
 
73
76
  def test_text_to_utf8
74
- f = File.open(File.join(File.dirname(__FILE__), 'artifacts/excel_different_types.txt'),'r')
77
+ f = File.open(File.join(File.dirname(__FILE__), "artifacts/excel_different_types.txt"), "r")
75
78
  t = f.read
76
79
  w = Workbook::Book.new
77
80
  t = w.text_to_utf8(t)
@@ -85,37 +88,37 @@ class TestWorkbook < Minitest::Test
85
88
  end
86
89
 
87
90
  def test_push_and_ltlt
88
- b = Workbook::Book.new [["a","b"],[1,2]]
89
- b.push Workbook::Sheet.new([["a","b"],[2,2]])
90
- b.push Workbook::Sheet.new([["a","b"],[3,2]])
91
- b << Workbook::Sheet.new([["a","b"],[4,2]])
92
- b.push Workbook::Sheet.new([["a","b"],[5,2]])
93
- b << Workbook::Sheet.new([["a","b"],[6,2]])
94
- b.push Workbook::Sheet.new([["a","b"],[7,2]])
91
+ b = Workbook::Book.new [["a", "b"], [1, 2]]
92
+ b.push Workbook::Sheet.new([["a", "b"], [2, 2]])
93
+ b.push Workbook::Sheet.new([["a", "b"], [3, 2]])
94
+ b << Workbook::Sheet.new([["a", "b"], [4, 2]])
95
+ b.push Workbook::Sheet.new([["a", "b"], [5, 2]])
96
+ b << Workbook::Sheet.new([["a", "b"], [6, 2]])
97
+ b.push Workbook::Sheet.new([["a", "b"], [7, 2]])
95
98
 
96
99
  # puts b.index b.last
97
- 7.times { |time| assert_equal(b,b[0].book) }
100
+ 7.times { |time| assert_equal(b, b[0].book) }
98
101
  end
99
102
 
100
103
  def test_removal_of_sheets_pop_and_delete_at_works_as_expected
101
- b = Workbook::Book.new [["a","b"],[1,2]]
102
- b.push Workbook::Sheet.new([["a","b"],[2,2]])
103
- b.push Workbook::Sheet.new([["a","b"],[3,2]])
104
- b << Workbook::Sheet.new([["a","b"],[4,2]])
105
- b.push Workbook::Sheet.new([["a","b"],[5,2]])
106
- b << Workbook::Sheet.new([["a","b"],[6,2]])
107
- b.push Workbook::Sheet.new([["a","b"],[7,2]])
104
+ b = Workbook::Book.new [["a", "b"], [1, 2]]
105
+ b.push Workbook::Sheet.new([["a", "b"], [2, 2]])
106
+ b.push Workbook::Sheet.new([["a", "b"], [3, 2]])
107
+ b << Workbook::Sheet.new([["a", "b"], [4, 2]])
108
+ b.push Workbook::Sheet.new([["a", "b"], [5, 2]])
109
+ b << Workbook::Sheet.new([["a", "b"], [6, 2]])
110
+ b.push Workbook::Sheet.new([["a", "b"], [7, 2]])
108
111
 
109
112
  assert_equal(7, b.count)
110
- assert_equal(5,b[4][0][1][0].value)
113
+ assert_equal(5, b[4][0][1][0].value)
111
114
  b.delete_at(4)
112
115
  assert_equal(6, b.count)
113
- assert_equal(6,b[4][0][1][0].value)
116
+ assert_equal(6, b[4][0][1][0].value)
114
117
  b.pop(3)
115
118
  assert_equal(3, b.count)
116
119
  end
117
120
 
118
121
  def test_supported_mime_types
119
- assert_equal true, Workbook::SUPPORTED_MIME_TYPES.include?('text/csv')
122
+ assert_equal true, Workbook::SUPPORTED_MIME_TYPES.include?("text/csv")
120
123
  end
121
124
  end
data/test/test_column.rb CHANGED
@@ -1,30 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
 
6
5
  class TestColumn < Minitest::Test
7
-
8
6
  def new_table
9
7
  Workbook::Table.new([
10
- ["a","b","c","d"],
11
- [true,3.2,"asdf",1],
12
- [true,3.2,"asdf",1],
13
- [false,3.2,"asdf",1],
14
- [true,3.2,"asdf",1]
15
- ])
8
+ ["a", "b", "c", "d"],
9
+ [true, 3.2, "asdf", 1],
10
+ [true, 3.2, "asdf", 1],
11
+ [false, 3.2, "asdf", 1],
12
+ [true, 3.1, "asdf", 1]
13
+ ])
16
14
  end
17
15
 
18
16
  def test_init
19
17
  c = Workbook::Column.new
20
18
  assert_equal(Workbook::Column, c.class)
21
- c = Workbook::Column.new(nil, {:limit=>20,:default=>"asdf", :column_type=>:boolean})
22
- c = Workbook::Column.new(Workbook::Table.new, {:limit=>20,:default=>"asdf", :column_type=>:boolean})
19
+ c = Workbook::Column.new(Workbook::Table.new, {limit: 20, default: "asdf", column_type: :boolean})
23
20
  assert_equal(20, c.limit)
24
21
  assert_equal(Workbook::Cell.new("asdf"), c.default)
25
22
  assert_equal(:boolean, c.column_type)
26
23
  assert_raises(ArgumentError) { Workbook::Column.new(true) }
27
- assert_raises(ArgumentError) { Workbook::Column.new(nil, {:limit=>20,:default=>"asdf", :column_type=>:bodfolean}) }
24
+ assert_raises(ArgumentError) { Workbook::Column.new(nil, {limit: 20, default: "asdf", column_type: :bodfolean}) }
28
25
  end
29
26
 
30
27
  def test_table
@@ -42,26 +39,31 @@ class TestColumn < Minitest::Test
42
39
 
43
40
  def test_column_type
44
41
  t = new_table
45
- assert_equal([:boolean, :float, :string, :integer], t.columns.collect{|a| a.column_type})
42
+ assert_equal([:boolean, :float, :string, :integer], t.columns.collect { |a| a.column_type })
46
43
  t = new_table
47
44
  t.last.last.value = 1.1
48
- assert_equal([:boolean, :float, :string, :string], t.columns.collect{|a| a.column_type})
45
+ assert_equal([:boolean, :float, :string, :string], t.columns.collect { |a| a.column_type })
49
46
  t = new_table
50
47
  t[2][3] = nil
51
- assert_equal([:boolean, :float, :string, :integer], t.columns.collect{|a| a.column_type})
48
+ assert_equal([:boolean, :float, :string, :integer], t.columns.collect { |a| a.column_type })
52
49
  t = new_table
53
50
  t[2].delete_at(3)
54
- assert_equal([:boolean, :float, :string, :integer], t.columns.collect{|a| a.column_type})
51
+ assert_equal([:boolean, :float, :string, :integer], t.columns.collect { |a| a.column_type })
55
52
  end
56
53
 
57
54
  def test_alpha_index_to_number_index
58
- assert_equal(0,Workbook::Column.alpha_index_to_number_index("A"))
59
- assert_equal(2,Workbook::Column.alpha_index_to_number_index("C"))
60
- assert_equal(25,Workbook::Column.alpha_index_to_number_index("Z"))
61
- assert_equal(26,Workbook::Column.alpha_index_to_number_index("AA"))
62
- assert_equal(27,Workbook::Column.alpha_index_to_number_index("AB"))
63
- assert_equal(51,Workbook::Column.alpha_index_to_number_index("AZ"))
64
- assert_equal(52,Workbook::Column.alpha_index_to_number_index("BA"))
65
- assert_equal((27*26)-1,Workbook::Column.alpha_index_to_number_index("ZZ"))
55
+ assert_equal(0, Workbook::Column.alpha_index_to_number_index("A"))
56
+ assert_equal(2, Workbook::Column.alpha_index_to_number_index("C"))
57
+ assert_equal(25, Workbook::Column.alpha_index_to_number_index("Z"))
58
+ assert_equal(26, Workbook::Column.alpha_index_to_number_index("AA"))
59
+ assert_equal(27, Workbook::Column.alpha_index_to_number_index("AB"))
60
+ assert_equal(51, Workbook::Column.alpha_index_to_number_index("AZ"))
61
+ assert_equal(52, Workbook::Column.alpha_index_to_number_index("BA"))
62
+ assert_equal((27 * 26) - 1, Workbook::Column.alpha_index_to_number_index("ZZ"))
63
+ end
64
+
65
+ def test_cells
66
+ assert_equal([3.2,3.2,3.2,3.1], new_table.columns[1].cells.map(&:value))
67
+ assert_equal([3.2,3.2,3.2,3.1], new_table.columns[1].map(&:value))
66
68
  end
67
69
  end
data/test/test_format.rb CHANGED
@@ -1,34 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
 
6
5
  class TestFormat < Minitest::Test
7
-
8
-
9
6
  def test_initialize
10
7
  f = Workbook::Format.new {}
11
- assert_equal({},f)
12
- f = Workbook::Format.new({:background=>:red})
13
- assert_equal({:background=>:red},f)
14
- f = Workbook::Format.new({:background=>:red})
8
+ assert_equal({}, f)
9
+ f = Workbook::Format.new({background: :red})
10
+ assert_equal({background: :red}, f)
11
+ f = Workbook::Format.new({background: :red})
15
12
  deet = Time.now
16
- assert_equal(false,f.has_raw_for?(Time))
13
+ assert_equal(false, f.has_raw_for?(Time))
17
14
 
18
15
  f.add_raw deet
19
- assert_equal(deet,f.raws[Time])
20
- assert_equal(true,f.has_raw_for?(Time))
21
-
16
+ assert_equal(deet, f.raws[Time])
17
+ assert_equal(true, f.has_raw_for?(Time))
22
18
  end
23
19
 
24
20
  def test_derived_type
25
21
  f = Workbook::Format.new {}
26
22
  assert_nil(f.derived_type)
27
23
  f = Workbook::Format.new numberformat: "%m/%e/%y h:%m"
28
- assert_equal(:time,f.derived_type)
24
+ assert_equal(:time, f.derived_type)
29
25
  f = Workbook::Format.new numberformat: "%m/%e/%y"
30
- assert_equal(:date,f.derived_type)
31
-
26
+ assert_equal(:date, f.derived_type)
32
27
  end
33
28
 
34
29
  def test_available_raws
@@ -40,80 +35,81 @@ class TestFormat < Minitest::Test
40
35
  end
41
36
 
42
37
  def test_merge
43
- a = Workbook::Format.new({:background=>:red})
44
- b = Workbook::Format.new({:background=>:yellow, :color=>:green})
38
+ a = Workbook::Format.new({background: :red})
39
+ b = Workbook::Format.new({background: :yellow, color: :green})
45
40
  result = b.clone.merge(a)
46
- assert_equal({:background=>:red, :color=>:green},result)
47
- assert_equal(true,result.is_a?(Workbook::Format))
41
+ assert_equal({background: :red, color: :green}, result)
42
+ assert_equal(true, result.is_a?(Workbook::Format))
48
43
  end
49
44
 
50
45
  def test_remove_raw_on_merge
51
- a = Workbook::Format.new({:background=>:red})
52
- b = Workbook::Format.new({:background=>:yellow, :color=>:green})
46
+ a = Workbook::Format.new({background: :red})
47
+ b = Workbook::Format.new({background: :yellow, color: :green})
53
48
  b.add_raw Date.new
54
49
  result = b.clone.merge(a)
55
- assert_equal({},result.raws)
50
+ assert_equal({}, result.raws)
56
51
  end
57
52
 
58
53
  def test_has_background_color?
59
54
  a = Workbook::Format.new
60
- assert_equal(false,a.has_background_color?)
61
- a = Workbook::Format.new({:background_color=>'#ff0000'})
62
- assert_equal(true,a.has_background_color?)
63
- assert_equal(false,a.has_background_color?('#00ff00'))
64
- a = Workbook::Format.new({:background_color=>'#ffffff'})
65
- assert_equal(false,a.has_background_color?)
66
- a = Workbook::Format.new({:background_color=>'#FFFFFf'})
67
- assert_equal(false,a.has_background_color?)
68
-
69
-
55
+ assert_equal(false, a.has_background_color?)
56
+ a = Workbook::Format.new({background_color: "#ff0000"})
57
+ assert_equal(true, a.has_background_color?)
58
+ assert_equal(false, a.has_background_color?("#00ff00"))
59
+ a = Workbook::Format.new({background_color: "#ffffff"})
60
+ assert_equal(false, a.has_background_color?)
61
+ a = Workbook::Format.new({background_color: "#FFFFFf"})
62
+ assert_equal(false, a.has_background_color?)
70
63
  end
71
64
 
72
65
  def test_to_css
73
- a = Workbook::Format.new({:background_color=>'#ffffff'})
74
- assert_equal("background: #ffffff",a.to_css)
75
- a = Workbook::Format.new({:background_color=>'#fffdff', :color=>:red})
76
- assert_equal("background: #fffdff; color: red",a.to_css)
77
-
66
+ a = Workbook::Format.new({background_color: "#ffffff"})
67
+ assert_equal("background: #ffffff", a.to_css)
68
+ a = Workbook::Format.new({background_color: "#fffdff", color: :red})
69
+ assert_equal("background: #fffdff; color: red", a.to_css)
78
70
  end
79
71
 
80
72
  def test_parent_style
81
- a = Workbook::Format.new({:background_color=>'#ffffff'})
82
- b = Workbook::Format.new({:color=>'#000'})
73
+ a = Workbook::Format.new({background_color: "#ffffff"})
74
+ b = Workbook::Format.new({color: "#000"})
83
75
  a.parent = b
84
76
  assert_equal(b, a.parent)
85
77
  end
78
+
86
79
  def test_parent_style_flattened_properties
87
- a = Workbook::Format.new({:background_color=>'#ffffff'})
88
- b = Workbook::Format.new({:color=>'#000'})
80
+ a = Workbook::Format.new({background_color: "#ffffff"})
81
+ b = Workbook::Format.new({color: "#000"})
89
82
  a.parent = b
90
- assert_equal(Workbook::Format.new({:color=>'#000',:background_color=>'#ffffff'}), a.flattened)
91
- c = Workbook::Format.new({:color=>'#f00'})
83
+ assert_equal(Workbook::Format.new({color: "#000", background_color: "#ffffff"}), a.flattened)
84
+ c = Workbook::Format.new({color: "#f00"})
92
85
  c.parent = a
93
- assert_equal(Workbook::Format.new({:color=>'#f00',:background_color=>'#ffffff'}), c.flattened)
86
+ assert_equal(Workbook::Format.new({color: "#f00", background_color: "#ffffff"}), c.flattened)
94
87
  end
88
+
95
89
  def test_formats
96
- a = Workbook::Format.new({:background_color=>'#ffffff'})
97
- b = Workbook::Format.new({:color=>'#000'})
98
- c = Workbook::Format.new({:color=>'#f00'})
90
+ a = Workbook::Format.new({background_color: "#ffffff"})
91
+ b = Workbook::Format.new({color: "#000"})
92
+ c = Workbook::Format.new({color: "#f00"})
99
93
  a.parent = b
100
94
  c.parent = a
101
- assert_equal([b,a,c], c.formats)
95
+ assert_equal([b, a, c], c.formats)
102
96
  end
97
+
103
98
  def test_parent_style_to_css
104
- a = Workbook::Format.new({:background_color=>'#ffffff'})
105
- b = Workbook::Format.new({:color=>'#000'})
106
- c = Workbook::Format.new({:color=>'#f00'})
99
+ a = Workbook::Format.new({background_color: "#ffffff"})
100
+ b = Workbook::Format.new({color: "#000"})
101
+ c = Workbook::Format.new({color: "#f00"})
107
102
  a.parent = b
108
103
  c.parent = a
109
104
  assert_equal("background: #ffffff; color: #f00", c.to_css)
110
105
  end
106
+
111
107
  def test_all_names
112
- a = Workbook::Format.new({:background_color=>'#ffffff'}, "a")
113
- b = Workbook::Format.new({:color=>'#000'},"b")
114
- c = Workbook::Format.new({:color=>'#f00'},"c")
108
+ a = Workbook::Format.new({background_color: "#ffffff"}, "a")
109
+ b = Workbook::Format.new({color: "#000"}, "b")
110
+ c = Workbook::Format.new({color: "#f00"}, "c")
115
111
  a.parent = b
116
112
  c.parent = a
117
- assert_equal(["b","a","c"],c.all_names)
113
+ assert_equal(["b", "a", "c"], c.all_names)
118
114
  end
119
115
  end
@@ -1,17 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
 
6
5
  class TestFunctional < Minitest::Test
7
- def test_chapter_Initializing
6
+ def test_chapter_initializing
8
7
  b = Workbook::Book.new
9
8
  assert_equal(Workbook::Book, b.class)
10
9
  s = b.sheet
11
10
  assert_equal(Workbook::Sheet, s.class)
12
11
  t = s.table
13
12
  assert_equal(Workbook::Table, t.class)
14
- s = b.sheet[0] = Workbook::Sheet.new([['a','b'],[1,2],[3,4],[5,6]])
13
+ s = b.sheet[0] = Workbook::Sheet.new([["a", "b"], [1, 2], [3, 4], [5, 6]])
15
14
  assert_equal(Workbook::Sheet, s.class)
16
15
 
17
16
  t = s.table
@@ -20,14 +19,14 @@ class TestFunctional < Minitest::Test
20
19
  assert_equal(Workbook::Cell, t.first.first.class)
21
20
  assert_equal(true, t.header.header?)
22
21
  assert_equal(false, t.last.header?)
23
- assert_equal(2,t[1][:b].value)
22
+ assert_equal(2, t[1][:b].value)
24
23
  end
25
24
 
26
- def test_chapter_Sorting
25
+ def test_chapter_sorting
27
26
  # b = Workbook::Book.new
28
27
  # s = b.sheet[0] = Workbook::Sheet.new([['a','b'],[1,2],[3,4],[5,6]])
29
28
  # t = s.table
30
- #t.sort_by {|r| r[:b]}
31
- #p t.inspect
29
+ # t.sort_by {|r| r[:b]}
30
+ # p t.inspect
32
31
  end
33
32
  end
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require File.join(File.dirname(__FILE__), 'helper')
3
+ require File.join(File.dirname(__FILE__), "helper")
5
4
 
6
5
  class TestToCacheClass
7
6
  include Workbook::Modules::Cache
8
7
  def basic_fetch
9
- fetch_cache(:a){
8
+ fetch_cache(:a) {
10
9
  sleep(0.5)
11
10
  "return"
12
11
  }
13
12
  end
13
+
14
14
  def expiring_fetch
15
- fetch_cache(:a,Time.now+0.6){
15
+ fetch_cache(:a, Time.now + 0.6) {
16
16
  sleep(0.5)
17
17
  "return"
18
18
  }
@@ -26,29 +26,31 @@ module Modules
26
26
  c.debug_cache = false
27
27
  start_time = Time.now
28
28
  c.basic_fetch
29
- diff_time = Time.now-start_time
30
- assert_equal(true,(diff_time > 0.5 and diff_time < 0.51))
29
+ diff_time = Time.now - start_time
30
+ assert_equal(true, ((diff_time > 0.5) && (diff_time < 0.51)))
31
31
  c.basic_fetch
32
- diff_time = Time.now-start_time
33
- assert_equal(true,(diff_time > 0.5 and diff_time < 0.51))
32
+ diff_time = Time.now - start_time
33
+ assert_equal(true, ((diff_time > 0.5) && (diff_time < 0.51)))
34
34
  c.basic_fetch
35
- diff_time = Time.now-start_time
36
- assert_equal(true,(diff_time > 0.5 and diff_time < 0.51))
35
+ diff_time = Time.now - start_time
36
+ assert_equal(true, ((diff_time > 0.5) && (diff_time < 0.51)))
37
37
  end
38
+
38
39
  def test_basic_fetch_invalidate_cache!
39
40
  c = TestToCacheClass.new
40
41
  start_time = Time.now
41
42
  c.basic_fetch
42
- diff_time = Time.now-start_time
43
- assert_equal(true,(diff_time > 0.5 and diff_time < 0.51))
43
+ diff_time = Time.now - start_time
44
+ assert_equal(true, ((diff_time > 0.5) && (diff_time < 0.51)))
44
45
  c.basic_fetch
45
- diff_time = Time.now-start_time
46
- assert_equal(true,(diff_time > 0.5 and diff_time < 0.51))
46
+ diff_time = Time.now - start_time
47
+ assert_equal(true, ((diff_time > 0.5) && (diff_time < 0.51)))
47
48
  c.invalidate_cache!
48
49
  c.basic_fetch
49
- diff_time = Time.now-start_time
50
- assert_equal(true,(diff_time > 1 and diff_time < 1.01))
50
+ diff_time = Time.now - start_time
51
+ assert_equal(true, ((diff_time > 1) && (diff_time < 1.01)))
51
52
  end
53
+
52
54
  def test_basic_fetch_invalidate_by_expiration
53
55
  # c = TestToCacheClass.new
54
56
  # start_time = Time.now
@@ -65,6 +67,5 @@ module Modules
65
67
  # diff_time = Time.now-start_time
66
68
  # assert_equal(true,(diff_time > 1 and diff_time < 1.01))
67
69
  end
68
-
69
70
  end
70
71
  end