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 +4 -4
- data/lib/arc-furnace/excel_source.rb +47 -19
- data/lib/arc-furnace/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c35f10203b2279c62249355a6c9fe3b5bea5926f
|
4
|
+
data.tar.gz: 7b028a8348e8a07193488436fdb4b7f0375172a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: ,
|
10
|
+
def initialize(filename:, sheet: nil, group_by: false, key_column: nil)
|
11
11
|
@excel = Roo::Excelx.new(filename)
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
19
|
-
@excel.close if @excel
|
20
|
-
end
|
19
|
+
alias_method :group_by?, :group_by
|
21
20
|
|
22
21
|
def preprocess
|
23
|
-
|
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
|
-
|
36
|
-
yielder <<
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
data/lib/arc-furnace/version.rb
CHANGED
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.
|
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-
|
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.
|
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
|