rxl 0.5.1 → 0.6.0
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/README.md +35 -29
- data/lib/rxl.rb +2 -2
- data/lib/rxl/version.rb +1 -1
- data/lib/workbook.rb +2 -4
- data/lib/worksheet.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de4749440f95c5322dd8ebd53fbe5cb404ea1fb74cf8f8f3ccb5075bf8546a13
|
4
|
+
data.tar.gz: 45c65180dff5b3ea3caa4e419b6dbc484bc3f08ec893c498bd0eefa292dc03a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d14ae0ec6967b65750b93b5bd83f586f709f54ec59d6b67d88c79f2eae50121532520714f104eda924615d246ed8ff5a5c466d9a5485c96bd81b07fab91eb828
|
7
|
+
data.tar.gz: 04fb929742e396df0798f59d92fdb78b98d93be0c303a13fb5c30a25d6b3596ffc438c59570f4354776822c90a870ad45eef2b2a7f9da1d442c2126dd6e72314
|
data/README.md
CHANGED
@@ -10,6 +10,10 @@ The mechanics of the conversion between xlsx and ruby hash have been implemented
|
|
10
10
|
|
11
11
|
https://github.com/weshatheleopard/rubyXL
|
12
12
|
|
13
|
+
## Breaking changes
|
14
|
+
|
15
|
+
Version 0.6.0 introduces a breaking change in the format of inputs for writing as tables, refer to revised documentation below.
|
16
|
+
|
13
17
|
## Installation
|
14
18
|
|
15
19
|
Add this line to your application's Gemfile:
|
@@ -240,35 +244,37 @@ TODO: add full description for hash_cell_to_rubyxl_cell and rubyxl_cell_to_hash_
|
|
240
244
|
To write a file as pass the filename and hash:
|
241
245
|
|
242
246
|
```ruby
|
243
|
-
Rxl.write_file_as_tables('path/to/save.xlsx', hash_tables
|
247
|
+
Rxl.write_file_as_tables('path/to/save.xlsx', hash_tables)
|
244
248
|
```
|
245
249
|
|
246
|
-
The worksheets' top row will be populated with values specified in the `
|
250
|
+
The worksheets' top row will be populated with values specified in the `columns` array. Those array items will also be used to extract the current row from the current hash.
|
247
251
|
|
248
|
-
* use `nil` in the `
|
252
|
+
* use `nil` in the `columns` array to leave blank columns (including blank header)
|
249
253
|
* string or symbol keys can be used, so long as the key in order is the same as in the hashes
|
250
254
|
|
251
255
|
The format of the excel hash_workbook has sheet names as keys and hashes of rows as values:
|
252
256
|
|
253
257
|
```ruby
|
254
|
-
order = %i[header_a header_b]
|
255
258
|
hash_tables = {
|
256
|
-
'Sheet1' =>
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
259
|
+
'Sheet1' => {
|
260
|
+
columns: %i[header_a header_b],
|
261
|
+
rows: [
|
262
|
+
{
|
263
|
+
header_a: 'some_value',
|
264
|
+
header_b: 'other_value'
|
265
|
+
},
|
266
|
+
{
|
267
|
+
header_a: 'some_value',
|
268
|
+
header_b: 'other_value'
|
269
|
+
}
|
270
|
+
]
|
271
|
+
}
|
266
272
|
}
|
267
273
|
```
|
268
274
|
|
269
275
|
#### Formatting for tables
|
270
276
|
|
271
|
-
Add formatting to tables by adding a `:formats` key to the
|
277
|
+
Add formatting to tables by adding a `:formats` key to the sheet hash.
|
272
278
|
|
273
279
|
Inside the formatting hash add child hashes with keys for the relevant table.
|
274
280
|
|
@@ -279,10 +285,10 @@ Formatting for rows is not currently implemented.
|
|
279
285
|
Additionally inside the table hash add a key `:headers` with a cell hash (excluding `:value`) to set formatting for the header row.
|
280
286
|
|
281
287
|
```ruby
|
282
|
-
order = %i[header_a header_b]
|
283
288
|
hash_tables = {
|
284
|
-
|
285
|
-
|
289
|
+
'Sheet1' => {
|
290
|
+
columns: %i[header_a header_b],
|
291
|
+
formats: {
|
286
292
|
headers: {
|
287
293
|
bold: true,
|
288
294
|
align: 'center'
|
@@ -290,18 +296,18 @@ hash_tables = {
|
|
290
296
|
'B' => {
|
291
297
|
fill: 'feb302'
|
292
298
|
}
|
293
|
-
}
|
294
|
-
},
|
295
|
-
'Sheet1' => [
|
296
|
-
{
|
297
|
-
'col_1' => 'some_value',
|
298
|
-
'col_2' => 'other_value'
|
299
299
|
},
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
300
|
+
rows: [
|
301
|
+
{
|
302
|
+
'col_1' => 'some_value',
|
303
|
+
'col_2' => 'other_value'
|
304
|
+
},
|
305
|
+
{
|
306
|
+
'col_1' => 'some_value',
|
307
|
+
'col_2' => 'other_value'
|
308
|
+
}
|
309
|
+
]
|
310
|
+
}
|
305
311
|
}
|
306
312
|
```
|
307
313
|
|
data/lib/rxl.rb
CHANGED
@@ -10,8 +10,8 @@ module Rxl
|
|
10
10
|
nil
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.write_file_as_tables(filepath, hash_tables,
|
14
|
-
hash_workbook = Workbook.hashes_to_hash_workbook(hash_tables,
|
13
|
+
def self.write_file_as_tables(filepath, hash_tables, write_headers: true)
|
14
|
+
hash_workbook = Workbook.hashes_to_hash_workbook(hash_tables, write_headers: write_headers)
|
15
15
|
write_file(filepath, hash_workbook)
|
16
16
|
nil
|
17
17
|
end
|
data/lib/rxl/version.rb
CHANGED
data/lib/workbook.rb
CHANGED
@@ -26,12 +26,10 @@ module Workbook
|
|
26
26
|
rubyxl_workbook
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.hashes_to_hash_workbook(hash_tables,
|
29
|
+
def self.hashes_to_hash_workbook(hash_tables, write_headers: true)
|
30
30
|
hash_workbook = {}
|
31
|
-
all_formats = hash_tables.delete(:formats) || {}
|
32
31
|
hash_tables.each do |k, v|
|
33
|
-
|
34
|
-
hash_workbook[k] = Worksheet.hashes_to_hash_worksheet(v, order, formats, write_headers: write_headers)
|
32
|
+
hash_workbook[k] = Worksheet.hashes_to_hash_worksheet(v[:rows], v[:columns], v[:formats] || {}, write_headers: write_headers)
|
35
33
|
end
|
36
34
|
hash_workbook
|
37
35
|
end
|
data/lib/worksheet.rb
CHANGED
@@ -38,11 +38,11 @@ module Worksheet
|
|
38
38
|
### GET RUBYXL WORKSHEET FROM HASHES ###
|
39
39
|
################################################
|
40
40
|
|
41
|
-
def self.hashes_to_hash_worksheet(hashes,
|
41
|
+
def self.hashes_to_hash_worksheet(hashes, columns, formats, write_headers: true)
|
42
42
|
rows = hashes.map do |hash|
|
43
|
-
|
43
|
+
columns.map { |item| hash[item] }
|
44
44
|
end
|
45
|
-
rows.unshift(
|
45
|
+
rows.unshift(columns.map { |item| "#{item}" }) if write_headers
|
46
46
|
hash_worksheet = rows_to_hash_worksheet(rows)
|
47
47
|
format_hash_worksheet(hash_worksheet, formats, write_headers) if formats
|
48
48
|
hash_worksheet
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rxl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian McWilliams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|