excel_utils 1.1.1 → 1.1.2

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: b318fb2a815346b8292031cf5236e0744525b919902eb5b81c288c8429399132
4
- data.tar.gz: 70d6e62cfcd662b4d5f913174e06119f45b3f69bf78d66b3c743277a6dcd81c6
3
+ metadata.gz: ea8c9b8aeb5945a6d01f5ea29578bf34c48d28f8a572cb6d5f3857757fb48ae9
4
+ data.tar.gz: f1fc9f86e3a3fe784184cd942739e3ea961f018ea313006222568785988b6f34
5
5
  SHA512:
6
- metadata.gz: 29a539fcab3a28fcd97f479c40840d2694286494e262fb66446567a11c28cffb9e6d6258df2470aec2c48959aa3f8170533a461e0f88b7a10b23eaa91a3503c6
7
- data.tar.gz: 4255935e350cda3a56d62da964e7c9d50c0cf8db194ae0cec39c20ba4ac0be12206d43583702d198cb9b55e4c617abe6b30462a9e407c7622683669e8599acee
6
+ metadata.gz: 0d7ef606b270f1af8ae88e91e12b44c657e693c7653c3df2d5b951d71758339749be6d78ee95a2c04f1e6895544cb653d8f84bae8ba619757bfc2b1bbb945dbe
7
+ data.tar.gz: 6eea2444670d88df36d2d4fdcca88ba4ced1ac9bfbc8890b8e2ab6b4c6b90d42a0413725599ea99e5bfc93f480bbd931cdc8516e725b04ed2c0a3c355ca00815
@@ -15,7 +15,7 @@ module ExcelUtils
15
15
  @column_names ||= begin
16
16
  if sheet.first_row
17
17
  first_row = sheet.row sheet.first_row
18
- normalize_column_names ? first_row.map { |n| Inflecto.underscore(n.strip.gsub(' ', '_')).to_sym } : first_row
18
+ normalize_column_names ? first_row.map { |name| normalize_column name } : first_row
19
19
  else
20
20
  []
21
21
  end
@@ -46,5 +46,9 @@ module ExcelUtils
46
46
  end
47
47
  end
48
48
 
49
+ def normalize_column(name)
50
+ Inflecto.underscore(name.strip.gsub(' ', '_')).to_sym
51
+ end
52
+
49
53
  end
50
54
  end
@@ -1,3 +1,3 @@
1
1
  module ExcelUtils
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
@@ -34,7 +34,7 @@ module ExcelUtils
34
34
  sheet = workbook.add_worksheet sheet_name
35
35
 
36
36
  if sheet_data.any?
37
- header = sheet_data.first.keys
37
+ header = sheet_data.flat_map(&:keys).uniq
38
38
  sheet.write_row 0, 0, header.map(&:to_s)
39
39
 
40
40
  sheet_data.each_with_index do |row, r|
@@ -17,7 +17,7 @@ describe ExcelUtils do
17
17
 
18
18
  data = {
19
19
  'Sheet 1' => [
20
- {'column_a' => 1.5, 'column_b' => 'text 1', 'column_c' => DateTime.parse('2019-05-25T16:30:00'), 'column_d' => '999'},
20
+ {'column_a' => 1.5, 'column_b' => 'text 1', 'column_c' => DateTime.parse('2019-05-25T16:30:00')},
21
21
  {'column_b' => 'text 2', 'column_c' => Date.parse('2019-07-09'), 'column_a' => 2, 'column_d' => '0123'},
22
22
  ],
23
23
  'Sheet 2' => [
@@ -30,7 +30,14 @@ describe ExcelUtils do
30
30
 
31
31
  workbook = ExcelUtils.read filename
32
32
 
33
- workbook.to_h.must_equal data
33
+ workbook.sheets.each do |sheet|
34
+ sheet.each_with_index do |row, i|
35
+ columns = row.keys | data[sheet.name][i].keys
36
+ columns.each do |column|
37
+ row[column].must_equal data[sheet.name][i][column]
38
+ end
39
+ end
40
+ end
34
41
  end
35
42
 
36
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-13 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflecto