rxl 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b102ae677e551c55e09c215bc2d1cce924fd7f2fc04ed62494688ace5ef97d0
4
- data.tar.gz: e27a358a15acd3ffe9fd7cb0fb28b80bffe1d34a5d4d39cd6daf8588e5f41bc0
3
+ metadata.gz: de4749440f95c5322dd8ebd53fbe5cb404ea1fb74cf8f8f3ccb5075bf8546a13
4
+ data.tar.gz: 45c65180dff5b3ea3caa4e419b6dbc484bc3f08ec893c498bd0eefa292dc03a3
5
5
  SHA512:
6
- metadata.gz: 16bc6449d64157ba6a930d38c6b2d37e5068e95a2e8c7aa9b0dab8577d4681e852b09b40f3e7cfaab9d428c819a8ca1eb6385ec4d83e37d46828c060aa9e27f4
7
- data.tar.gz: b7036aaa8fde48fd7c5f5967623c04170c11f8aca19567aa9c21525a23ab8bbe3ae516951718f5ff9eede77d059bade248b0f796e20a44ae372fdc1696c34d77
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, order)
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 `order` array. Those array items will also be used to extract the current row from the current hash.
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 `order` array to leave blank columns (including blank header)
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
- header_a: 'some_value',
259
- header_b: 'other_value'
260
- },
261
- {
262
- header_a: 'some_value',
263
- header_b: 'other_value'
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 top level hash.
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
- formats: {
285
- 'Sheet1' => {
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
- 'col_1' => 'some_value',
302
- 'col_2' => 'other_value'
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, order, write_headers: true)
14
- hash_workbook = Workbook.hashes_to_hash_workbook(hash_tables, order, write_headers: write_headers)
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
@@ -1,3 +1,3 @@
1
1
  module Rxl
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -26,12 +26,10 @@ module Workbook
26
26
  rubyxl_workbook
27
27
  end
28
28
 
29
- def self.hashes_to_hash_workbook(hash_tables, order, write_headers: true)
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
- formats = all_formats[k]
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
@@ -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, order, formats, write_headers: true)
41
+ def self.hashes_to_hash_worksheet(hashes, columns, formats, write_headers: true)
42
42
  rows = hashes.map do |hash|
43
- order.map { |item| hash[item] }
43
+ columns.map { |item| hash[item] }
44
44
  end
45
- rows.unshift(order.map { |item| "#{item}" }) if write_headers
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.5.1
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-02-17 00:00:00.000000000 Z
11
+ date: 2019-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler