arc-furnace 0.1.30 → 0.1.31

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
  SHA1:
3
- metadata.gz: d2faf523ade797107093de338836f4cf729280b6
4
- data.tar.gz: d44a2695905ba74e5ff6dde9900c093fec51698a
3
+ metadata.gz: c35f10203b2279c62249355a6c9fe3b5bea5926f
4
+ data.tar.gz: 7b028a8348e8a07193488436fdb4b7f0375172a5
5
5
  SHA512:
6
- metadata.gz: 56f4db95b3f40082f98ceaa065f42267b2ba09cb62eba19a18df1a908f1fd95a7ee36ead23e9be508ed1e09f85ac501cf7cb1707212cfa279908ae54d9032975
7
- data.tar.gz: aaa3aaf2b622b2846b887c3f1cd67a014d14c48bc7ce27d7cd354c9b530307c8eb72c8db9e49fa4efda8950173c6ec82b1b187194597991c1623dc2d1e6c9d1c
6
+ metadata.gz: bbe2cc9797ca5544d0d75cb873a912b2150323b7f8e6d4ed67940d859eca9a0a75643f9231fb63c16d8579c466835d6d18a1167f649e78c77bfa8a90bb7c333b
7
+ data.tar.gz: 567a87f7cbc709875a9522d98dc859529af0cc82d8cfa590f06deba7553c86b0d8439eff7f4aa9ca678b41ceecd2a69c90448dd9f8603d0d5cfe0bd8d349bf1c
@@ -5,22 +5,35 @@ module ArcFurnace
5
5
  class ExcelSource < EnumeratorSource
6
6
 
7
7
  private_attr_reader :excel, :header_row
8
- attr_reader :value
8
+ attr_reader :value, :group_by, :key_column
9
9
 
10
- def initialize(filename: , sheet: nil)
10
+ def initialize(filename:, sheet: nil, group_by: false, key_column: nil)
11
11
  @excel = Roo::Excelx.new(filename)
12
- if sheet
13
- excel.default_sheet = sheet
14
- end
12
+ @preprocessed_excel = []
13
+ @group_by = group_by
14
+ @key_column = key_column
15
+ excel.default_sheet = sheet if sheet
15
16
  super()
16
17
  end
17
18
 
18
- def close
19
- @excel.close if @excel
20
- end
19
+ alias_method :group_by?, :group_by
21
20
 
22
21
  def preprocess
23
- enumerator.next
22
+ if group_by?
23
+ build_headers
24
+ group_rows
25
+ else
26
+ enumerator.next
27
+ end
28
+ end
29
+
30
+ def build_headers
31
+ @header_row = excel.first
32
+ end
33
+
34
+ def group_rows
35
+ @excel.each_row_streaming { |row| @preprocessed_excel << build_row(row) }
36
+ @preprocessed_excel = @preprocessed_excel.group_by { |row| row[key_column] }
24
37
  end
25
38
 
26
39
  def extract_cell_value(cell)
@@ -30,21 +43,36 @@ module ArcFurnace
30
43
  end
31
44
  end
32
45
 
46
+ def build_row(row)
47
+ row.each_with_object({}) do |cell, result|
48
+ value = extract_cell_value(cell)
49
+ result[header_row[cell.coordinate.column - 1]] = value if value
50
+ end
51
+ end
52
+
33
53
  def build_enumerator
34
54
  Enumerator.new do |yielder|
35
- excel.each_row_streaming do |row|
36
- yielder <<
37
- if header_row
38
- row.each_with_object({}) do |cell, result|
39
- value = extract_cell_value(cell)
40
- result[header_row[cell.coordinate.column - 1]] = value if value
41
- end
42
- else
43
- # First time, return the header row so we can save it.
44
- @header_row = row.map { |value| extract_cell_value(value) }
55
+ if group_by?
56
+ @preprocessed_excel.each { |_, array| yielder << array }
57
+ else
58
+ excel.each_row_streaming do |row|
59
+ yielder << if header_row
60
+ row.each_with_object({}) do |cell, result|
61
+ value = extract_cell_value(cell)
62
+ result[header_row[cell.coordinate.column - 1]] = value if value
45
63
  end
64
+ else
65
+ # First time, return the header row so we can save it.
66
+ @header_row = row.map { |value| extract_cell_value(value) }
67
+ end
68
+ end
46
69
  end
47
70
  end
48
71
  end
72
+
73
+ def close
74
+ @excel.close if @excel
75
+ end
76
+
49
77
  end
50
78
  end
@@ -1,3 +1,3 @@
1
1
  module ArcFurnace
2
- VERSION = "0.1.30"
2
+ VERSION = "0.1.31"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arc-furnace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.30
4
+ version: 0.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Spangenberger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-03-29 00:00:00.000000000 Z
12
+ date: 2018-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  requirements: []
232
232
  rubyforge_project:
233
- rubygems_version: 2.6.13
233
+ rubygems_version: 2.4.5.1
234
234
  signing_key:
235
235
  specification_version: 4
236
236
  summary: Melds and transforms data from multiple sources into a single stream