workbook 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) 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 +8 -0
  7. data/Gemfile +2 -2
  8. data/README.md +9 -7
  9. data/Rakefile +6 -6
  10. data/json_test.json +1 -0
  11. data/lib/workbook/book.rb +73 -62
  12. data/lib/workbook/cell.rb +58 -13
  13. data/lib/workbook/column.rb +31 -28
  14. data/lib/workbook/format.rb +23 -24
  15. data/lib/workbook/generatetypes.rb +4 -4
  16. data/lib/workbook/modules/cache.rb +6 -7
  17. data/lib/workbook/modules/cell.rb +77 -100
  18. data/lib/workbook/modules/diff_sort.rb +92 -83
  19. data/lib/workbook/modules/raw_objects_storage.rb +6 -8
  20. data/lib/workbook/modules/type_parser.rb +30 -22
  21. data/lib/workbook/nil_value.rb +4 -9
  22. data/lib/workbook/readers/csv_reader.rb +7 -10
  23. data/lib/workbook/readers/ods_reader.rb +51 -50
  24. data/lib/workbook/readers/txt_reader.rb +6 -8
  25. data/lib/workbook/readers/xls_reader.rb +21 -33
  26. data/lib/workbook/readers/xls_shared.rb +106 -117
  27. data/lib/workbook/readers/xlsx_reader.rb +45 -46
  28. data/lib/workbook/row.rb +99 -84
  29. data/lib/workbook/sheet.rb +47 -38
  30. data/lib/workbook/table.rb +96 -72
  31. data/lib/workbook/template.rb +12 -15
  32. data/lib/workbook/types/false.rb +0 -1
  33. data/lib/workbook/types/nil.rb +0 -1
  34. data/lib/workbook/types/nil_class.rb +1 -1
  35. data/lib/workbook/types/numeric.rb +1 -1
  36. data/lib/workbook/types/string.rb +1 -1
  37. data/lib/workbook/types/time.rb +1 -1
  38. data/lib/workbook/types/true.rb +0 -1
  39. data/lib/workbook/types/true_class.rb +1 -1
  40. data/lib/workbook/version.rb +2 -3
  41. data/lib/workbook/writers/csv_table_writer.rb +10 -13
  42. data/lib/workbook/writers/html_writer.rb +34 -38
  43. data/lib/workbook/writers/json_table_writer.rb +8 -11
  44. data/lib/workbook/writers/xls_writer.rb +30 -36
  45. data/lib/workbook/writers/xlsx_writer.rb +45 -29
  46. data/lib/workbook.rb +16 -15
  47. data/test/artifacts/currency_test.ods +0 -0
  48. data/test/helper.rb +6 -5
  49. data/test/test_book.rb +41 -38
  50. data/test/test_column.rb +26 -24
  51. data/test/test_format.rb +51 -55
  52. data/test/test_functional.rb +7 -8
  53. data/test/test_modules_cache.rb +18 -17
  54. data/test/test_modules_cell.rb +55 -46
  55. data/test/test_modules_table_diff_sort.rb +55 -64
  56. data/test/test_modules_type_parser.rb +61 -31
  57. data/test/test_readers_csv_reader.rb +48 -42
  58. data/test/test_readers_ods_reader.rb +36 -31
  59. data/test/test_readers_txt_reader.rb +21 -23
  60. data/test/test_readers_xls_reader.rb +20 -23
  61. data/test/test_readers_xls_shared.rb +2 -3
  62. data/test/test_readers_xlsx_reader.rb +44 -37
  63. data/test/test_row.rb +105 -109
  64. data/test/test_sheet.rb +35 -41
  65. data/test/test_table.rb +82 -60
  66. data/test/test_template.rb +16 -15
  67. data/test/test_types_date.rb +4 -6
  68. data/test/test_writers_csv_writer.rb +24 -0
  69. data/test/test_writers_html_writer.rb +42 -41
  70. data/test/test_writers_json_writer.rb +16 -9
  71. data/test/test_writers_xls_writer.rb +50 -35
  72. data/test/test_writers_xlsx_writer.rb +62 -34
  73. data/workbook.gemspec +25 -27
  74. metadata +96 -42
@@ -1,36 +1,34 @@
1
1
  # frozen_string_literal: true
2
-
3
- # -*- encoding : utf-8 -*-
4
2
  # frozen_string_literal: true
5
- require 'spreadsheet'
3
+
4
+ require "spreadsheet"
6
5
 
7
6
  module Workbook
8
7
  module Writers
9
8
  module HtmlWriter
10
-
11
9
  # Generates an HTML table ()
12
10
  #
13
11
  # @param [Hash] options A hash with options
14
12
  # @return [String] A String containing the HTML code
15
- def to_html options={}
16
- builder = Nokogiri::XML::Builder.new do |doc|
13
+ def to_html options = {}
14
+ builder = Nokogiri::XML::Builder.new { |doc|
17
15
  doc.html {
18
16
  doc.body {
19
- self.each{|sheet|
20
- doc.h1 {
17
+ each do |sheet|
18
+ doc.h1 do
21
19
  doc.text sheet.name
22
- }
23
- sheet.each{|table|
24
- doc.h2 {
20
+ end
21
+ sheet.each do |table|
22
+ doc.h2 do
25
23
  doc.text table.name
26
- }
24
+ end
27
25
  doc << table.to_html(options)
28
- }
29
- }
26
+ end
27
+ end
30
28
  }
31
29
  }
32
- end
33
- return builder.doc.to_xhtml
30
+ }
31
+ builder.doc.to_xhtml
34
32
  end
35
33
 
36
34
  # Write the current workbook to HTML format
@@ -39,9 +37,9 @@ module Workbook
39
37
  # @param [Hash] options see #to_xls
40
38
  # @return [String] filename
41
39
 
42
- def write_to_html filename="#{title}.html", options={}
43
- File.open(filename, 'w') {|f| f.write(to_html(options)) }
44
- return filename
40
+ def write_to_html filename = "#{title}.html", options = {}
41
+ File.open(filename, "w") { |f| f.write(to_html(options)) }
42
+ filename
45
43
  end
46
44
  end
47
45
 
@@ -50,16 +48,16 @@ module Workbook
50
48
  #
51
49
  # @param [Hash] options A hash with options
52
50
  # @return [String] A String containing the HTML code, most importantly `:style_with_inline_css` (default false)
53
- def to_html options={}
54
- options = {:style_with_inline_css=>false}.merge(options)
55
- builder = Nokogiri::XML::Builder.new do |doc|
51
+ def to_html options = {}
52
+ options = {style_with_inline_css: false}.merge(options)
53
+ builder = Nokogiri::XML::Builder.new { |doc|
56
54
  doc.table do
57
55
  doc.thead do
58
56
  if header
59
57
  doc.tr do
60
58
  header.each do |cell|
61
59
  th_options = build_cell_options cell, options.merge(classnames: [cell.to_sym], data: {key: cell.to_sym})
62
- unless cell.value.class == Workbook::NilValue
60
+ unless cell.value.instance_of?(Workbook::NilValue)
63
61
  doc.th(th_options) do
64
62
  doc.text cell.value
65
63
  end
@@ -69,12 +67,12 @@ module Workbook
69
67
  end
70
68
  end
71
69
  doc.tbody do
72
- self.each do |row|
70
+ each do |row|
73
71
  unless row.header?
74
72
  doc.tr do
75
73
  row.each do |cell|
76
74
  td_options = build_cell_options cell, options
77
- unless cell.value.class == Workbook::NilValue
75
+ unless cell.value.instance_of?(Workbook::NilValue)
78
76
  doc.td(td_options) do
79
77
  doc.text cell.value
80
78
  end
@@ -85,24 +83,22 @@ module Workbook
85
83
  end
86
84
  end
87
85
  end
88
- end
89
- return builder.doc.to_xhtml
86
+ }
87
+ builder.doc.to_xhtml
90
88
  end
91
89
 
92
- def build_cell_options cell, options={}
90
+ def build_cell_options cell, options = {}
93
91
  classnames = cell.format.all_names
94
- classnames = classnames + options[:classnames] if options[:classnames]
92
+ classnames += options[:classnames] if options[:classnames]
95
93
  classnames = classnames.join(" ").strip
96
- td_options = classnames != "" ? {:class=>classnames} : {}
97
- if options[:data]
98
- options[:data].each do |key, value|
99
- td_options = td_options.merge({("data-#{key}".to_sym) => value})
100
- end
94
+ td_options = classnames != "" ? {class: classnames} : {}
95
+ options[:data]&.each do |key, value|
96
+ td_options = td_options.merge({"data-#{key}".to_sym => value})
101
97
  end
102
- td_options = td_options.merge({:style=>cell.format.to_css}) if options[:style_with_inline_css] and cell.format.to_css != ""
103
- td_options = td_options.merge({:colspan=>cell.colspan}) if cell.colspan
104
- td_options = td_options.merge({:rowspan=>cell.rowspan}) if cell.rowspan
105
- return td_options
98
+ td_options = td_options.merge({style: cell.format.to_css}) if options[:style_with_inline_css] && (cell.format.to_css != "")
99
+ td_options = td_options.merge({colspan: cell.colspan}) if cell.colspan
100
+ td_options = td_options.merge({rowspan: cell.rowspan}) if cell.rowspan
101
+ td_options
106
102
  end
107
103
  end
108
104
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
-
3
- # -*- encoding : utf-8 -*-
4
2
  # frozen_string_literal: true
5
- require 'json'
3
+
4
+ require "json"
6
5
 
7
6
  module Workbook
8
7
  module Writers
@@ -11,7 +10,7 @@ module Workbook
11
10
  #
12
11
  # @param [Hash] options
13
12
  # @return [String] json string
14
- def to_json options={}
13
+ def to_json options = {}
15
14
  JSON.generate(to_array_of_hashes_with_values(options))
16
15
  end
17
16
 
@@ -19,9 +18,8 @@ module Workbook
19
18
  #
20
19
  # @param [Hash] options
21
20
  # @return [Array<Hash>] array with hashes (comma separated values in a string)
22
- def to_array_of_hashes_with_values options={}
23
- array_of_hashes = self.collect{|a| a.to_hash_with_values unless a.header?}.compact
24
- return array_of_hashes
21
+ def to_array_of_hashes_with_values options = {}
22
+ collect { |a| a.to_hash_with_values unless a.header? }.compact
25
23
  end
26
24
 
27
25
  # Write the current workbook to JSON format
@@ -29,11 +27,10 @@ module Workbook
29
27
  # @param [String] filename
30
28
  # @param [Hash] options see #to_json
31
29
  # @return [String] filename
32
- def write_to_json filename="#{title}.json", options={}
33
- File.open(filename, 'w') {|f| f.write(to_json(options)) }
34
- return filename
30
+ def write_to_json filename = "#{title}.json", options = {}
31
+ File.open(filename, "w") { |f| f.write(to_json(options)) }
32
+ filename
35
33
  end
36
-
37
34
  end
38
35
  end
39
36
  end
@@ -1,30 +1,28 @@
1
1
  # frozen_string_literal: true
2
-
3
- # -*- encoding : utf-8 -*-
4
2
  # frozen_string_literal: true
5
- require 'spreadsheet'
3
+
4
+ require "spreadsheet"
6
5
 
7
6
  module Workbook
8
7
  module Writers
9
8
  module XlsWriter
10
-
11
9
  # Generates an Spreadsheet (from the spreadsheet gem) in order to build an xls
12
10
  #
13
11
  # @param [Hash] options A hash with options (unused so far)
14
12
  # @return [Spreadsheet] A Spreadsheet object, ready for writing or more lower level operations
15
- def to_xls options={}
13
+ def to_xls options = {}
16
14
  book = init_spreadsheet_template
17
- self.each_with_index do |s,si|
15
+ each_with_index do |s, si|
18
16
  xls_sheet = xls_sheet(si)
19
17
  xls_sheet.name = s.name
20
18
 
21
19
  s.table.each_with_index do |r, ri|
22
- xls_sheet.row(ri).height= r.format[:height] if r.format
20
+ xls_sheet.row(ri).height = r.format[:height] if r.format
23
21
  r.each_with_index do |c, ci|
24
22
  if c
25
23
  if r.first?
26
- xls_sheet.columns[ci] ||= Spreadsheet::Column.new(ci,nil)
27
- xls_sheet.columns[ci].width= c.format[:width]
24
+ xls_sheet.columns[ci] ||= Spreadsheet::Column.new(ci, nil)
25
+ xls_sheet.columns[ci].width = c.format[:width]
28
26
  end
29
27
  xls_sheet.row(ri)[ci] = c.value
30
28
  xls_sheet.row(ri).set_format(ci, format_to_xls_format(c.format))
@@ -32,12 +30,11 @@ module Workbook
32
30
  end
33
31
  end
34
32
  (xls_sheet.last_row_index + 1 - s.table.count).times do |time|
35
- row_to_remove = s.table.count+time
36
- remove_row(xls_sheet,row_to_remove)
33
+ row_to_remove = s.table.count + time
34
+ remove_row(xls_sheet, row_to_remove)
37
35
  end
38
36
  xls_sheet.updated_from(s.table.count)
39
37
  xls_sheet.dimensions
40
-
41
38
  end
42
39
  # kind of a hack, deleting by popping from xls worksheet results in errors in MS Excel (not LibreOffice)
43
40
  # book.worksheets.pop(book.worksheets.count - self.count) if book.worksheets and book.worksheets.count > self.count
@@ -46,10 +43,10 @@ module Workbook
46
43
  xls_sheet.visibility = :visible
47
44
  else
48
45
  xls_sheet.visibility = :strong_hidden
49
- #also make sure all data is removed, in case someone finds out about this 'trick'
46
+ # also make sure all data is removed, in case someone finds out about this 'trick'
50
47
  xls_sheet.name = "RemovedSheet#{si}"
51
48
  (xls_sheet.last_row_index + 1).times do |row_index|
52
- remove_row(xls_sheet,row_index)
49
+ remove_row(xls_sheet, row_index)
53
50
  end
54
51
  end
55
52
  end
@@ -58,20 +55,17 @@ module Workbook
58
55
  book
59
56
  end
60
57
 
61
-
62
-
63
58
  # Generates an Spreadsheet (from the spreadsheet gem) in order to build an XlS
64
59
  #
65
60
  # @param [Workbook::Format, Hash] f A Workbook::Format or hash with format-options (:font_weight, :rotation, :background_color, :number_format, :text_direction, :color, :font_family)
66
61
  # @return [Spreadsheet::Format] A Spreadsheet format-object, ready for writing or more lower level operations
67
62
  def format_to_xls_format f
68
- xlsfmt = nil
69
63
  unless f.is_a? Workbook::Format
70
64
  f = Workbook::Format.new f
71
65
  end
72
66
  xlsfmt = f.return_raw_for Spreadsheet::Format
73
67
  unless xlsfmt
74
- xlsfmt=Spreadsheet::Format.new :weight=>f[:font_weight]
68
+ xlsfmt = Spreadsheet::Format.new weight: f[:font_weight]
75
69
  xlsfmt.rotation = f[:rotation] if f[:rotation]
76
70
  xlsfmt.pattern_fg_color = html_color_to_xls_color(f[:background_color]) if html_color_to_xls_color(f[:background_color])
77
71
  xlsfmt.pattern = 1 if html_color_to_xls_color(f[:background_color])
@@ -83,7 +77,7 @@ module Workbook
83
77
  xlsfmt.font.color = color if color
84
78
  f.add_raw xlsfmt
85
79
  end
86
- return xlsfmt
80
+ xlsfmt
87
81
  end
88
82
 
89
83
  # Parses right font-family name
@@ -91,20 +85,20 @@ module Workbook
91
85
  # @param [Workbook::Format, hash] format to parse
92
86
  def parse_font_family(format)
93
87
  font = format[:font_family].to_s.split.last
94
- valid_values = [:none,:roman,:swiss,:modern,:script,:decorative]
88
+ valid_values = [:none, :roman, :swiss, :modern, :script, :decorative]
95
89
  if valid_values.include?(font)
96
- return font
90
+ font
97
91
  elsif valid_values.include?(font.to_s.downcase.to_sym)
98
- return font.to_s.downcase.to_sym
92
+ font.to_s.downcase.to_sym
99
93
  else
100
94
  font = font.to_s.downcase.strip
101
95
  translation = {
102
- "arial"=>:swiss,
103
- "times"=>:roman,
104
- "times new roman"=>:roman
96
+ "arial" => :swiss,
97
+ "times" => :roman,
98
+ "times new roman" => :roman
105
99
  }
106
100
  tfont = translation[font]
107
- return tfont ? tfont : :none
101
+ tfont || :none
108
102
  end
109
103
  end
110
104
 
@@ -112,40 +106,40 @@ module Workbook
112
106
  #
113
107
  # @param [String] filename
114
108
  # @param [Hash] options see #to_xls
115
- def write_to_xls filename="#{title}.xls", options={}
109
+ def write_to_xls filename = "#{title}.xls", options = {}
116
110
  if to_xls(options).write(filename)
117
- return filename
111
+ filename
118
112
  end
119
113
  end
120
114
 
121
115
  def xls_sheet a
122
116
  if xls_template.worksheet(a)
123
- return xls_template.worksheet(a)
117
+ xls_template.worksheet(a)
124
118
  else
125
119
  xls_template.create_worksheet
126
- self.xls_sheet a
120
+ xls_sheet a
127
121
  end
128
122
  end
129
123
 
130
124
  def xls_template
131
- return template.raws[Spreadsheet::Excel::Workbook] ? template.raws[Spreadsheet::Excel::Workbook] : template.raws[Spreadsheet::Workbook]
125
+ template.raws[Spreadsheet::Excel::Workbook] || template.raws[Spreadsheet::Workbook]
132
126
  end
133
127
 
134
128
  def init_spreadsheet_template
135
- if self.xls_template.is_a? Spreadsheet::Workbook
136
- return self.xls_template
129
+ if xls_template.is_a? Spreadsheet::Workbook
130
+ xls_template
137
131
  else
138
132
  t = Spreadsheet::Workbook.new
139
133
  template.add_raw t
140
- return t
134
+ t
141
135
  end
142
136
  end
143
137
 
144
138
  private
145
139
 
146
- def remove_row(xls_sheet,row_index)
140
+ def remove_row(xls_sheet, row_index)
147
141
  xls_sheet.row(row_index).each_with_index do |c, ci|
148
- xls_sheet.row(row_index)[ci]=nil
142
+ xls_sheet.row(row_index)[ci] = nil
149
143
  end
150
144
  xls_sheet.delete_row(row_index)
151
145
  xls_sheet.row_updated(row_index, xls_sheet.row(row_index))
@@ -1,37 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- # frozen_string_literal: true
5
- require 'axlsx'
6
- require 'workbook/readers/xls_shared'
3
+ require "axlsx"
4
+ require "workbook/readers/xls_shared"
7
5
 
8
6
  module Workbook
9
7
  module Writers
10
8
  module XlsxWriter
11
-
9
+ CELL_TYPE_MAPPING = {
10
+ decimal: :integer,
11
+ integer: :integer,
12
+ float: :float,
13
+ string: :text,
14
+ time: :time,
15
+ date: :date,
16
+ datetime: :time,
17
+ boolean: :boolean,
18
+ nil: :string
19
+ }
12
20
  # Generates an axlsx doc, ready for export to XLSX
13
21
  #
14
22
  # @param [Hash] options A hash with options (unused so far)
15
23
  # @return [Axlsx::Package] An object, ready for writing or more lower level operations
16
- def to_xlsx options={}
24
+ def to_xlsx options = {}
17
25
  formats_to_xlsx_format
26
+
18
27
  book = init_xlsx_spreadsheet_template.workbook
19
- book.worksheets.pop(book.worksheets.count - self.count) if book.worksheets and book.worksheets.count > self.count
20
- self.each_with_index do |s,si|
28
+ book.worksheets.pop(book.worksheets.count - count) if book.worksheets && (book.worksheets.count > count)
29
+ each_with_index do |s, si|
21
30
  xlsx_sheet = xlsx_sheet(si)
22
31
  xlsx_sheet.name = s.name
23
32
  s.table.each_with_index do |r, ri|
24
- xlsx_row = xlsx_sheet[ri] ? xlsx_sheet[ri] : xlsx_sheet.add_row
33
+ xlsx_row = xlsx_sheet[ri] || xlsx_sheet.add_row
25
34
  xlsx_row.height = 16
26
35
  xlsx_row_a = xlsx_row.to_ary
27
36
  r.each_with_index do |c, ci|
28
37
  xlsx_row.add_cell(c.value) unless xlsx_row_a[ci]
29
38
  xlsx_cell = xlsx_row_a[ci]
39
+
40
+ xlsx_cell.type = CELL_TYPE_MAPPING[c.cell_type]
30
41
  xlsx_cell.value = c.value
31
- # if c.format?
32
- # format_to_xlsx_format(c.format) unless c.format.raws[Fixnum]
33
- # xlsx_cell.style = c.format.raws[Fixnum]
34
- # end
42
+
43
+ if c.format? && c.format.raws[Integer]
44
+ xlsx_cell.style = c.format.raws[Integer]
45
+ elsif c.format? && !(c.value.is_a?(Date) || !c.value.is_a?(DateTime) || !c.value.is_a?(Time))
46
+ # TODO: disable formatting
47
+ # xlsx_cell.style = format_to_xlsx_format(c.format)
48
+ end
35
49
  end
36
50
  xlsx_sheet.send(:update_column_info, xlsx_row.cells, [])
37
51
  end
@@ -54,39 +68,39 @@ module Workbook
54
68
  #
55
69
  # @param [String] filename
56
70
  # @param [Hash] options see #to_xlsx
57
- def write_to_xlsx filename="#{title}.xlsx", options={}
71
+ def write_to_xlsx filename = "#{title}.xlsx", options = {}
58
72
  if to_xlsx(options).serialize(filename)
59
- return filename
73
+ filename
60
74
  end
61
75
  end
62
76
 
63
77
  def xlsx_sheet a
64
78
  if xlsx_template.workbook.worksheets[a]
65
- return xlsx_template.workbook.worksheets[a]
79
+ xlsx_template.workbook.worksheets[a]
66
80
  else
67
81
  xlsx_template.workbook.add_worksheet
68
- self.xlsx_sheet a
82
+ xlsx_sheet a
69
83
  end
70
84
  end
71
85
 
72
86
  def xlsx_template
73
- return template.raws[Axlsx::Package]
87
+ template.raws[Axlsx::Package]
74
88
  end
75
89
 
76
90
  def init_xlsx_spreadsheet_template
77
- if self.xlsx_template.is_a? Axlsx::Package
78
- return self.xlsx_template
91
+ if xlsx_template.is_a? Axlsx::Package
92
+ xlsx_template
79
93
  else
80
94
  t = Axlsx::Package.new
81
95
  template.add_raw t
82
96
  # template.set_default_formats!
83
- return t
97
+ t
84
98
  end
85
99
  end
86
100
 
87
101
  def formats_to_xlsx_format
88
- template.formats.each do |n,v|
89
- v.each do | t,s |
102
+ template.formats.each do |n, v|
103
+ v.each do |t, s|
90
104
  format_to_xlsx_format(s)
91
105
  end
92
106
  end
@@ -99,20 +113,22 @@ module Workbook
99
113
  def format_to_xlsx_format f
100
114
  f = make_sure_f_is_a_workbook_format f
101
115
 
102
- xlsfmt={}
103
- xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".gsub("#",'') if f[:color]
104
- xlsfmt[:b] = true if f[:font_weight].to_s == "bold" or f[:font_weight].to_i >= 600 or f[:"font_style"].to_s.match "oblique"
116
+ xlsfmt = {}
117
+ xlsfmt[:fg_color] = "FF#{f[:color].to_s.upcase}".delete("#") if f[:color]
118
+ xlsfmt[:b] = true if (f[:font_weight].to_s == "bold") || (f[:font_weight].to_i >= 600) || f[:font_style].to_s.match("oblique")
105
119
  xlsfmt[:i] = true if f[:font_style].to_s == "italic"
106
- xlsfmt[:u] = true if f[:text_decoration].to_s.match("underline")
120
+ xlsfmt[:u] = true if f[:text_decoration].to_s.include?("underline")
107
121
  xlsfmt[:bg_color] = f[:background_color] if f[:background_color]
108
122
  xlsfmt[:format_code] = strftime_to_ms_format(f[:number_format]) if f[:number_format]
109
123
  xlsfmt[:font_name] = f[:font_family].split.first if f[:font_family]
110
124
  # xlsfmt[:family] = parse_font_family(f) if f[:font_family]
111
125
 
112
- f.add_raw init_xlsx_spreadsheet_template.workbook.styles.add_style(xlsfmt)
126
+ style_reference = init_xlsx_spreadsheet_template.workbook.styles.add_style(xlsfmt)
127
+
128
+ f.add_raw style_reference
113
129
  f.add_raw xlsfmt
114
130
 
115
- return xlsfmt
131
+ style_reference
116
132
  end
117
133
  end
118
134
  end
data/lib/workbook.rb CHANGED
@@ -1,30 +1,31 @@
1
1
  # frozen_string_literal: true
2
-
3
- # -*- encoding : utf-8 -*-
4
2
  # frozen_string_literal: true
5
- require_relative 'workbook/modules/cache'
6
- require_relative 'workbook/modules/cell'
7
- require_relative 'workbook/types/date'
8
- require_relative 'workbook/book'
9
- require_relative 'workbook/sheet'
10
- require_relative 'workbook/table'
11
- require_relative 'workbook/nil_value'
12
- require_relative 'workbook/row'
13
- require_relative 'workbook/cell'
14
- require_relative 'workbook/format'
15
- require_relative 'workbook/template'
16
- require_relative 'workbook/version'
17
- require_relative 'workbook/column'
3
+
4
+ require_relative "workbook/modules/cache"
5
+ require_relative "workbook/modules/cell"
6
+ require_relative "workbook/types/date"
7
+ require_relative "workbook/book"
8
+ require_relative "workbook/sheet"
9
+ require_relative "workbook/table"
10
+ require_relative "workbook/nil_value"
11
+ require_relative "workbook/row"
12
+ require_relative "workbook/cell"
13
+ require_relative "workbook/format"
14
+ require_relative "workbook/template"
15
+ require_relative "workbook/version"
16
+ require_relative "workbook/column"
18
17
 
19
18
  module Workbook
20
19
  class << self
21
20
  def caching_enabled?
22
21
  @@caching_enabled ||= true
23
22
  end
23
+
24
24
  # Disable caching globally (wherever applicable)
25
25
  def disable_caching!
26
26
  @@caching_enabled = false
27
27
  end
28
+
28
29
  # Enable caching globally (wherever applicable)
29
30
  def enable_caching!
30
31
  @@caching_enabled = true
Binary file
data/test/helper.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- encoding : utf-8 -*-
4
- require 'minitest/autorun'
5
- # require 'test/unit'
6
- require 'rubygems'
7
- require File.join(File.dirname(__FILE__), '../lib/workbook')
3
+ require "simplecov"
4
+ SimpleCov.start
5
+
6
+ require "minitest/autorun"
7
+ require "rubygems"
8
+ require File.join(File.dirname(__FILE__), "../lib/workbook")