workbook 0.8.0 → 0.8.2
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.
- 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 +16 -0
- data/Gemfile +4 -2
- data/README.md +9 -7
- data/Rakefile +9 -7
- data/lib/workbook/book.rb +74 -61
- data/lib/workbook/cell.rb +59 -12
- data/lib/workbook/column.rb +33 -29
- data/lib/workbook/format.rb +24 -23
- data/lib/workbook/generatetypes.rb +6 -5
- data/lib/workbook/modules/cache.rb +8 -7
- data/lib/workbook/modules/cell.rb +78 -99
- data/lib/workbook/modules/diff_sort.rb +93 -82
- data/lib/workbook/modules/raw_objects_storage.rb +7 -7
- data/lib/workbook/modules/type_parser.rb +31 -21
- data/lib/workbook/nil_value.rb +5 -9
- data/lib/workbook/readers/csv_reader.rb +7 -9
- data/lib/workbook/readers/ods_reader.rb +49 -49
- data/lib/workbook/readers/txt_reader.rb +7 -7
- data/lib/workbook/readers/xls_reader.rb +22 -32
- data/lib/workbook/readers/xls_shared.rb +107 -116
- data/lib/workbook/readers/xlsx_reader.rb +47 -46
- data/lib/workbook/row.rb +100 -83
- data/lib/workbook/sheet.rb +48 -37
- data/lib/workbook/table.rb +97 -71
- data/lib/workbook/template.rb +13 -14
- data/lib/workbook/types/date.rb +2 -1
- data/lib/workbook/types/false.rb +1 -1
- data/lib/workbook/types/false_class.rb +2 -1
- data/lib/workbook/types/nil.rb +1 -1
- data/lib/workbook/types/nil_class.rb +3 -2
- data/lib/workbook/types/numeric.rb +3 -2
- data/lib/workbook/types/string.rb +3 -2
- data/lib/workbook/types/time.rb +3 -2
- data/lib/workbook/types/true.rb +1 -1
- data/lib/workbook/types/true_class.rb +3 -2
- data/lib/workbook/version.rb +3 -2
- data/lib/workbook/writers/csv_table_writer.rb +11 -12
- data/lib/workbook/writers/html_writer.rb +35 -37
- data/lib/workbook/writers/json_table_writer.rb +9 -10
- data/lib/workbook/writers/xls_writer.rb +31 -35
- data/lib/workbook/writers/xlsx_writer.rb +46 -28
- data/lib/workbook.rb +17 -14
- data/test/helper.rb +8 -5
- data/test/test_book.rb +43 -38
- data/test/test_column.rb +29 -25
- data/test/test_format.rb +53 -55
- data/test/test_functional.rb +9 -8
- data/test/test_modules_cache.rb +20 -17
- data/test/test_modules_cell.rb +49 -46
- data/test/test_modules_table_diff_sort.rb +56 -63
- data/test/test_modules_type_parser.rb +63 -31
- data/test/test_readers_csv_reader.rb +50 -42
- data/test/test_readers_ods_reader.rb +30 -31
- data/test/test_readers_txt_reader.rb +23 -23
- data/test/test_readers_xls_reader.rb +22 -23
- data/test/test_readers_xls_shared.rb +5 -4
- data/test/test_readers_xlsx_reader.rb +46 -37
- data/test/test_row.rb +107 -109
- data/test/test_sheet.rb +43 -35
- data/test/test_table.rb +84 -60
- data/test/test_template.rb +18 -15
- data/test/test_types_date.rb +7 -7
- data/test/test_writers_csv_writer.rb +24 -0
- data/test/test_writers_html_writer.rb +44 -41
- data/test/test_writers_json_writer.rb +11 -9
- data/test/test_writers_xls_writer.rb +52 -35
- data/test/test_writers_xlsx_writer.rb +64 -34
- data/workbook.gemspec +26 -27
- metadata +93 -27
data/lib/workbook/sheet.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
# frozen_string_literal: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
3
4
|
module Workbook
|
4
5
|
# A Sheet is a container of tables
|
5
|
-
class Sheet
|
6
|
-
|
6
|
+
class Sheet
|
7
|
+
include Enumerable
|
7
8
|
# Initialize a new sheet
|
8
9
|
#
|
9
10
|
# @param [Workbook::Table, Array<Array>] table The first table of this sheet
|
10
11
|
# @param [Workbook::Book] book The book this sheet belongs to
|
11
12
|
# @param [Hash] options are forwarded to Workbook::Table.new
|
12
13
|
# @return [Workbook::Sheet] (self)
|
13
|
-
def initialize table=Workbook::Table.new([], self), book=nil, options={}
|
14
|
-
|
15
|
-
|
14
|
+
def initialize table = Workbook::Table.new([], self), book = nil, options = {}
|
15
|
+
@tables = []
|
16
|
+
|
17
|
+
if table.is_a?(Workbook::Table)
|
18
|
+
@tables.push table
|
16
19
|
else
|
17
|
-
push
|
20
|
+
@tables.push(Workbook::Table.new(table, self, options))
|
18
21
|
end
|
19
22
|
self.book = book
|
20
|
-
return self
|
21
23
|
end
|
22
24
|
|
23
25
|
# Returns true if the first table of this sheet contains anything
|
@@ -31,79 +33,88 @@ module Workbook
|
|
31
33
|
#
|
32
34
|
# @return [Workbook::Table] the first table of this sheet
|
33
35
|
def table
|
34
|
-
first
|
36
|
+
@tables.first
|
35
37
|
end
|
36
38
|
|
37
39
|
# Returns the name of this sheet
|
38
40
|
#
|
39
41
|
# @return [String] the name, defaulting to sheet#index when none is set
|
40
42
|
def name
|
41
|
-
@name ||= "Sheet #{book.index(self)+1}"
|
43
|
+
@name ||= "Sheet #{book.index(self) + 1}"
|
42
44
|
end
|
43
45
|
|
44
46
|
# Set the name of this sheet
|
45
47
|
#
|
46
48
|
# @param [String] the new name of the sheet
|
47
49
|
# @return [String] the given name
|
48
|
-
|
49
|
-
@name = name
|
50
|
-
end
|
50
|
+
attr_writer :name
|
51
51
|
|
52
52
|
# Set the first table of this sheet with a table or array of cells/values
|
53
53
|
# @param [Workbook::Table, Array<Array>] table The new first table of this sheet
|
54
54
|
# @param [Hash] options are forwarded to Workbook::Table.new
|
55
55
|
# @return [Workbook::Table] the first table of this sheet
|
56
|
-
def table= table, options={}
|
57
|
-
if table.is_a? Workbook::Table
|
58
|
-
|
56
|
+
def table= table, options = {}
|
57
|
+
@tables[0] = if table.is_a? Workbook::Table
|
58
|
+
table
|
59
59
|
else
|
60
|
-
|
60
|
+
Workbook::Table.new(table, self, options)
|
61
61
|
end
|
62
|
-
return table
|
63
62
|
end
|
64
63
|
|
65
|
-
# Returns the
|
64
|
+
# Returns the Book this Sheet belongs to
|
66
65
|
#
|
67
66
|
# @return [Workbook::Book] the book this sheet belongs to
|
68
67
|
def book
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
@book || (self.book = Workbook::Book.new(self))
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns a existing or new Table at the specified index
|
72
|
+
#
|
73
|
+
# @return [Workbook::Table]
|
74
|
+
def [] index
|
75
|
+
@tables[index] ||= Workbook::Table.new([], self)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Inserts a new Table at the specified index
|
79
|
+
#
|
80
|
+
# @param [Integer] index of the table
|
81
|
+
# @param [Workbook::Table, Array<Array>] table The new first table of this sheet
|
82
|
+
#
|
83
|
+
# @return [Workbook::Table]
|
84
|
+
def []= index, value
|
85
|
+
table_to_insert = value.is_a?(Workbook::Table) ? value : Workbook::Table.new
|
86
|
+
table_to_insert.sheet = self
|
87
|
+
@tables[index] = table_to_insert
|
75
88
|
end
|
76
89
|
|
77
|
-
|
78
|
-
|
90
|
+
# Returns an enumerator
|
91
|
+
def each(...)
|
92
|
+
@tables.each(...)
|
79
93
|
end
|
80
94
|
|
95
|
+
attr_writer :book
|
96
|
+
|
81
97
|
# Removes all lines from this table
|
82
98
|
#
|
83
99
|
# @return [Workbook::Table] (self)
|
84
100
|
def delete_all
|
85
|
-
|
101
|
+
@tables.delete_if { |b| true }
|
86
102
|
end
|
87
103
|
|
88
104
|
# clones itself *and* the tables it contains
|
89
105
|
#
|
90
106
|
# @return [Workbook::Sheet] The cloned sheet
|
91
107
|
def clone
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
s.each{|t| c << t.clone}
|
96
|
-
return c
|
108
|
+
clone = super
|
109
|
+
@tables = @tables.map(&:clone)
|
110
|
+
clone
|
97
111
|
end
|
98
112
|
|
99
113
|
# Create or open the existing table at an index value
|
100
114
|
#
|
101
115
|
# @param [Integer] index the index of the table
|
102
116
|
def create_or_open_table_at index
|
103
|
-
|
104
|
-
t = self[index] = Workbook::Table.new if t == nil
|
105
|
-
t.sheet = self
|
106
|
-
t
|
117
|
+
self[index]
|
107
118
|
end
|
108
119
|
end
|
109
120
|
end
|
data/lib/workbook/table.rb
CHANGED
@@ -1,28 +1,35 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'workbook/writers/csv_table_writer'
|
5
|
-
require 'workbook/writers/json_table_writer'
|
6
|
-
require 'workbook/writers/html_writer'
|
2
|
+
# frozen_string_literal: true
|
7
3
|
|
4
|
+
require "workbook/modules/diff_sort"
|
5
|
+
require "workbook/writers/csv_table_writer"
|
6
|
+
require "workbook/writers/json_table_writer"
|
7
|
+
require "workbook/writers/html_writer"
|
8
8
|
|
9
9
|
module Workbook
|
10
10
|
# A table is a container of rows and keeps track of the sheet it belongs to and which row is its header. Additionally suport for CSV writing and diffing with another table is included.
|
11
|
-
class Table
|
11
|
+
class Table
|
12
|
+
include Enumerable
|
13
|
+
extend Forwardable
|
14
|
+
|
12
15
|
include Workbook::Modules::TableDiffSort
|
13
16
|
include Workbook::Writers::CsvTableWriter
|
14
17
|
include Workbook::Writers::JsonTableWriter
|
15
18
|
include Workbook::Writers::HtmlTableWriter
|
16
19
|
|
20
|
+
delegate [:first, :last, :pop, :delete_at, :each, :collect, :each_with_index, :count, :index, :delete_if, :include?] => :@rows
|
21
|
+
|
17
22
|
attr_accessor :name
|
23
|
+
attr_reader :rows
|
18
24
|
|
19
|
-
def initialize row_cel_values=[], sheet=nil, options={}
|
20
|
-
|
21
|
-
row_cel_values
|
25
|
+
def initialize row_cel_values = [], sheet = nil, options = {}
|
26
|
+
@rows = []
|
27
|
+
row_cel_values = [] if row_cel_values.nil?
|
28
|
+
row_cel_values.each_with_index do |r, ri|
|
22
29
|
if r.is_a? Workbook::Row
|
23
30
|
r.table = self
|
24
31
|
else
|
25
|
-
r = Workbook::Row.new(r,self, options)
|
32
|
+
r = Workbook::Row.new(r, self, options)
|
26
33
|
end
|
27
34
|
define_columns_with_row(r) if ri == 0
|
28
35
|
end
|
@@ -42,9 +49,9 @@ module Workbook
|
|
42
49
|
#
|
43
50
|
# @return [Workbook::Row] The header
|
44
51
|
def header
|
45
|
-
if defined?(@header)
|
52
|
+
if defined?(@header) && (@header == false)
|
46
53
|
false
|
47
|
-
elsif defined?(@header)
|
54
|
+
elsif defined?(@header) && @header
|
48
55
|
@header
|
49
56
|
else
|
50
57
|
first
|
@@ -57,10 +64,10 @@ module Workbook
|
|
57
64
|
# @param [Workbook::Row, Integer] h should be the row or the index of this table's row
|
58
65
|
# @return [Workbook::Row] The header
|
59
66
|
def header= h
|
60
|
-
if h.is_a? Numeric
|
61
|
-
|
67
|
+
@header = if h.is_a? Numeric
|
68
|
+
self[h]
|
62
69
|
else
|
63
|
-
|
70
|
+
h
|
64
71
|
end
|
65
72
|
end
|
66
73
|
|
@@ -68,7 +75,7 @@ module Workbook
|
|
68
75
|
#
|
69
76
|
# @return [Integer] The index of the header row (typically 0)
|
70
77
|
def header_row_index
|
71
|
-
|
78
|
+
@rows.map(&:object_id).index(header.object_id)
|
72
79
|
end
|
73
80
|
|
74
81
|
def define_columns_with_row(r)
|
@@ -81,16 +88,15 @@ module Workbook
|
|
81
88
|
#
|
82
89
|
# @param [Array, Workbook::Row] cell_values is an array or row of cell values
|
83
90
|
# @return [Workbook::Row] the newly created row
|
84
|
-
def new_row cell_values=[]
|
85
|
-
|
86
|
-
return r
|
91
|
+
def new_row cell_values = []
|
92
|
+
Workbook::Row.new(cell_values, self)
|
87
93
|
end
|
88
94
|
|
89
95
|
def create_or_open_row_at index
|
90
96
|
r = self[index]
|
91
|
-
if r
|
97
|
+
if r.nil?
|
92
98
|
r = Workbook::Row.new
|
93
|
-
r.table=
|
99
|
+
r.table = self
|
94
100
|
end
|
95
101
|
r
|
96
102
|
end
|
@@ -99,28 +105,40 @@ module Workbook
|
|
99
105
|
#
|
100
106
|
# @return [Workbook::Table] self
|
101
107
|
def remove_empty_lines!
|
102
|
-
|
108
|
+
delete_if { |r| r.nil? || r.compact.empty? }
|
103
109
|
self
|
104
110
|
end
|
105
111
|
|
106
112
|
# Add row
|
107
|
-
# @param [Workbook::Table, Array] row to add
|
108
|
-
def push(
|
109
|
-
|
110
|
-
|
111
|
-
|
113
|
+
# @param [Workbook::Table, Array] row(s) to add
|
114
|
+
def push(*args)
|
115
|
+
args.each do |arg|
|
116
|
+
self.<<(arg)
|
117
|
+
end
|
112
118
|
end
|
119
|
+
alias_method :append, :push
|
113
120
|
|
114
121
|
# Add row
|
115
122
|
# @param [Workbook::Table, Array] row to add
|
116
123
|
def <<(row)
|
117
|
-
row = Workbook::Row
|
118
|
-
super(row)
|
124
|
+
row = row.is_a?(Workbook::Row) ? row : Workbook::Row.new(row)
|
119
125
|
row.set_table(self)
|
126
|
+
@rows << row
|
127
|
+
end
|
128
|
+
|
129
|
+
# Insert row
|
130
|
+
# @param [Integer] index where to add
|
131
|
+
# @param [Array, Workbook::Row] row(s) to add
|
132
|
+
def insert index, *rows
|
133
|
+
rows.each_with_index do |row, i|
|
134
|
+
row = row.is_a?(Workbook::Row) ? row : Workbook::Row.new(row)
|
135
|
+
row.set_table(self)
|
136
|
+
row.insert(index + i, row)
|
137
|
+
end
|
120
138
|
end
|
121
139
|
|
122
140
|
def has_contents?
|
123
|
-
|
141
|
+
clone.remove_empty_lines!.count != 0
|
124
142
|
end
|
125
143
|
|
126
144
|
# Returns true if the row exists in this table
|
@@ -129,42 +147,43 @@ module Workbook
|
|
129
147
|
# @return [Boolean] whether the row exist in this table
|
130
148
|
def contains_row? row
|
131
149
|
raise ArgumentError, "table should be a Workbook::Row (you passed a #{t.class})" unless row.is_a?(Workbook::Row)
|
132
|
-
|
150
|
+
collect { |r| r.object_id }.include? row.object_id
|
133
151
|
end
|
134
152
|
|
135
153
|
# Returns the sheet this table belongs to, creates a new sheet if none exists
|
136
154
|
#
|
137
155
|
# @return [Workbook::Sheet] The sheet this table belongs to
|
138
156
|
def sheet
|
139
|
-
return @sheet if defined?(@sheet)
|
140
|
-
self.sheet= Workbook::Sheet.new(self)
|
157
|
+
return @sheet if defined?(@sheet) && !@sheet.nil?
|
158
|
+
self.sheet = Workbook::Sheet.new(self)
|
141
159
|
end
|
142
160
|
|
143
161
|
# Returns the sheet this table belongs to, creates a new sheet if none exists
|
144
162
|
#
|
145
163
|
# @param [Workbook::Sheet] sheet this table belongs to
|
146
164
|
# @return [Workbook::Sheet] The sheet this table belongs to
|
147
|
-
|
148
|
-
@sheet = sheet
|
149
|
-
end
|
165
|
+
attr_writer :sheet
|
150
166
|
|
151
167
|
# Removes all lines from this table
|
152
168
|
#
|
153
169
|
# @return [Workbook::Table] (self)
|
154
170
|
def delete_all
|
155
|
-
|
171
|
+
delete_if { |b| true }
|
156
172
|
end
|
157
173
|
|
158
174
|
# clones itself *and* the rows it contains
|
159
175
|
#
|
160
176
|
# @return [Workbook::Table] The cloned table
|
161
177
|
def clone
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
178
|
+
table_clone = super
|
179
|
+
@rows = @rows.map { |row|
|
180
|
+
cloned_row = row.clone
|
181
|
+
cloned_row.set_table(self)
|
182
|
+
cloned_row
|
183
|
+
}
|
184
|
+
self.header = @rows[header_row_index] if header_row_index
|
185
|
+
table_clone.header = table_clone.rows[header_row_index] if header_row_index
|
186
|
+
table_clone
|
168
187
|
end
|
169
188
|
|
170
189
|
# Overrides normal Array's []-function with support for symbols that identify a column based on the header-values
|
@@ -173,19 +192,25 @@ module Workbook
|
|
173
192
|
# table[0] #=> <Row [a,2,3,4]> (first row)
|
174
193
|
# table["A1"] #=> <Cell value="a"> (first cell of first row)
|
175
194
|
#
|
176
|
-
# @param [
|
195
|
+
# @param [Integer, String] index_or_string to reference to either the row, or the cell
|
177
196
|
# @return [Workbook::Row, Workbook::Cell, nil]
|
178
197
|
def [] index_or_string
|
179
198
|
if index_or_string.is_a? String
|
180
199
|
match = index_or_string.match(/([A-Z]+)([0-9]*)/i)
|
181
200
|
col_index = Workbook::Column.alpha_index_to_number_index(match[1])
|
182
|
-
|
183
|
-
|
201
|
+
if match[2] == ""
|
202
|
+
columns[col_index]
|
203
|
+
else
|
204
|
+
row_index = match[2].to_i - 1
|
205
|
+
@rows[row_index][col_index]
|
206
|
+
end
|
207
|
+
elsif index_or_string.is_a? Symbol
|
208
|
+
header[index_or_string].column
|
184
209
|
elsif index_or_string.is_a? Range
|
185
|
-
collection =
|
186
|
-
|
210
|
+
collection = @rows[index_or_string].collect { |a| a.clone }
|
211
|
+
Workbook::Table.new collection
|
187
212
|
elsif index_or_string.is_a? Integer
|
188
|
-
|
213
|
+
@rows[index_or_string]
|
189
214
|
end
|
190
215
|
end
|
191
216
|
|
@@ -196,7 +221,7 @@ module Workbook
|
|
196
221
|
# `table[0] = <Row [a,2,3,4]>` (set first row)
|
197
222
|
# `table["A1"] = 2` (set first cell of first row to 2)
|
198
223
|
#
|
199
|
-
# @param [
|
224
|
+
# @param [Integer, String] index_or_string to reference to either the row, or the cell
|
200
225
|
# @param [Workbook::Table, Array] new_value to set
|
201
226
|
# @return [Workbook::Cell, nil]
|
202
227
|
def []= index_or_string, new_value
|
@@ -204,65 +229,66 @@ module Workbook
|
|
204
229
|
match = index_or_string.upcase.match(/([A-Z]*)([0-9]*)/)
|
205
230
|
cell_index = Workbook::Column.alpha_index_to_number_index(match[1])
|
206
231
|
row_index = match[2].to_i - 1
|
207
|
-
|
232
|
+
@rows[row_index][cell_index].value = new_value
|
208
233
|
else
|
209
|
-
row = new_value
|
210
|
-
row =
|
211
|
-
super(index_or_string,row)
|
212
|
-
row.set_table(self)
|
234
|
+
row = new_value.is_a?(Workbook::Row) ? new_value : Workbook::Row.new(new_value)
|
235
|
+
row.table = self
|
213
236
|
end
|
214
237
|
end
|
215
238
|
|
239
|
+
def == other
|
240
|
+
to_csv == other.to_csv
|
241
|
+
end
|
242
|
+
|
216
243
|
# remove all the trailing empty-rows (returning a trimmed clone)
|
217
244
|
#
|
218
245
|
# @param [Integer] desired_row_length of the rows
|
219
246
|
# @return [Workbook::Row] a trimmed clone of the array
|
220
|
-
def trim desired_row_length=nil
|
221
|
-
|
247
|
+
def trim desired_row_length = nil
|
248
|
+
clone.trim!(desired_row_length)
|
222
249
|
end
|
223
250
|
|
224
251
|
# remove all the trailing empty-rows (returning a trimmed self)
|
225
252
|
#
|
226
253
|
# @param [Integer] desired_row_length of the new row
|
227
254
|
# @return [Workbook::Row] self
|
228
|
-
def trim! desired_row_length=nil
|
229
|
-
max_length =
|
230
|
-
self_count =
|
231
|
-
|
255
|
+
def trim! desired_row_length = nil
|
256
|
+
max_length = collect { |a| a.trim.length }.max
|
257
|
+
self_count = count - 1
|
258
|
+
count.times do |index|
|
232
259
|
index = self_count - index
|
233
|
-
if
|
234
|
-
|
260
|
+
if @rows[index].trim.empty?
|
261
|
+
delete_at(index)
|
235
262
|
else
|
236
263
|
break
|
237
264
|
end
|
238
265
|
end
|
239
|
-
|
266
|
+
each { |a| a.trim!(max_length) }
|
240
267
|
self
|
241
268
|
end
|
242
269
|
|
243
270
|
# Returns The dimensions of this sheet based on longest row
|
244
271
|
# @return [Array] x-width, y-height
|
245
272
|
def dimensions
|
246
|
-
height =
|
247
|
-
width =
|
248
|
-
[width,height]
|
273
|
+
height = count
|
274
|
+
width = collect { |a| a.length }.max
|
275
|
+
[width, height]
|
249
276
|
end
|
250
277
|
|
251
278
|
# Returns an array of Column-classes describing the columns of this table
|
252
279
|
# @return [Array<Column>] columns
|
253
280
|
def columns
|
254
|
-
@columns ||= header.collect
|
281
|
+
@columns ||= header.collect { |header_cell|
|
255
282
|
Column.new(self)
|
256
|
-
|
283
|
+
}
|
257
284
|
end
|
258
285
|
|
259
286
|
# Returns an array of Column-classes describing the columns of this table
|
260
287
|
# @param [Array<Column>] columns
|
261
288
|
# @return [Array<Column>] columns
|
262
289
|
def columns= columns
|
263
|
-
columns.each{|c| c.table=self}
|
290
|
+
columns.each { |c| c.table = self }
|
264
291
|
@columns = columns
|
265
292
|
end
|
266
|
-
|
267
293
|
end
|
268
294
|
end
|
data/lib/workbook/template.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
# frozen_string_literal: true
|
3
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "workbook/modules/raw_objects_storage"
|
4
5
|
|
5
6
|
module Workbook
|
6
7
|
# Workbook::Template is a container for different Workbook::Format's and the storage of raw template data that isn't really supported by Workbook, but should survive a typical read/write cyclus.
|
@@ -23,9 +24,9 @@ module Workbook
|
|
23
24
|
def add_format format
|
24
25
|
if format.is_a? Workbook::Format
|
25
26
|
if format.name
|
26
|
-
@formats[format.name]=format
|
27
|
+
@formats[format.name] = format
|
27
28
|
else
|
28
|
-
@formats[@formats.keys.count]=format
|
29
|
+
@formats[@formats.keys.count] = format
|
29
30
|
end
|
30
31
|
else
|
31
32
|
raise ArgumentError, "format should be a Workboot::Format"
|
@@ -34,31 +35,29 @@ module Workbook
|
|
34
35
|
|
35
36
|
# Return the list of associated formats
|
36
37
|
# @return [Hash] A keyed-hash of named formats
|
37
|
-
|
38
|
-
@formats
|
39
|
-
end
|
38
|
+
attr_reader :formats
|
40
39
|
|
41
40
|
# Create or find a format by name
|
42
41
|
# @return [Workbook::Format] The new or found format
|
43
42
|
# @param [String] name of the format (e.g. whatever you want, in diff names such as 'destroyed', 'updated' and 'created' are being used)
|
44
43
|
# @param [Symbol] variant can also be a strftime formatting string (e.g. "%Y-%m-%d")
|
45
|
-
def create_or_find_format_by name, variant
|
44
|
+
def create_or_find_format_by name, variant = :default
|
46
45
|
fs = @formats[name]
|
47
46
|
fs = @formats[name] = {} if fs.nil?
|
48
47
|
f = fs[variant]
|
49
48
|
if f.nil?
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
@formats[name][variant] = if (variant != :default) && fs[:default]
|
50
|
+
fs[:default].clone
|
51
|
+
else
|
52
|
+
Workbook::Format.new
|
53
53
|
end
|
54
|
-
@formats[name][variant] = f
|
55
54
|
end
|
56
|
-
|
55
|
+
@formats[name][variant]
|
57
56
|
end
|
58
57
|
|
59
58
|
def set_default_formats!
|
60
59
|
header_fmt = create_or_find_format_by :header
|
61
|
-
header_fmt[:font_weight] =
|
60
|
+
header_fmt[:font_weight] = "bold"
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
data/lib/workbook/types/date.rb
CHANGED
data/lib/workbook/types/false.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
# frozen_string_literal: true
|
1
|
+
# frozen_string_literal: true
|
data/lib/workbook/types/nil.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
# frozen_string_literal: true
|
1
|
+
# frozen_string_literal: true
|
data/lib/workbook/types/time.rb
CHANGED
data/lib/workbook/types/true.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
# frozen_string_literal: true
|
1
|
+
# frozen_string_literal: true
|