etl-pipeline 0.0.1 → 0.0.3
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 +1 -1
- data/lib/etl-pipeline.rb +62 -2
- data/lib/etl-pipeline/version.rb +1 -1
- data/spec/csv_parser_spec.rb +13 -0
- data/spec/model_base_spec.rb +37 -0
- data/spec/{etl-pipeline.rb → pipeline_spec.rb} +5 -1
- data/spec/spec_helper.rb +1 -0
- metadata +8 -5
- data/lib/etl-pipeline/csv_parser.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c169809c6cb4a6a3e856a07cd1affd8720c2269
|
4
|
+
data.tar.gz: 01e4de2a75ed5c50a950b500618d533cfd38170a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d4e50eae41efce5d232c7cfe9526fd81b4121c08a79c6be1db6f8a45ea754439ad38bf62db5553dc127557d929cd5eca988216ba51eaf0d9441a3493052d8ed
|
7
|
+
data.tar.gz: df4725bfd4597a0cef527fa1172e69240fd877af8e4fa7bfa86b73805e769c932c1f9841c5a4a755a512833174d3d8532440083db56c6bd414bc18fc6bee1ddd
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/elijahc/etl-pipeline)
|
4
4
|
|
5
|
-
|
5
|
+
[](http://badge.fury.io/rb/etl-pipeline)
|
6
6
|
|
7
7
|
[](https://coveralls.io/r/elijahc/pipeline)
|
8
8
|
|
data/lib/etl-pipeline.rb
CHANGED
@@ -2,17 +2,68 @@ require "etl-pipeline/version"
|
|
2
2
|
|
3
3
|
module Pipeline
|
4
4
|
module Parser
|
5
|
-
class
|
5
|
+
class Base
|
6
|
+
def parse
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class CSVParser < Pipeline::Parser::Base
|
11
|
+
attr_accessor :attribute_matrix, :model, :items
|
12
|
+
def initialize
|
13
|
+
@attribute_matrix = Hash.new
|
14
|
+
@items = Array.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def coerce(input, output)
|
18
|
+
@attribute_matrix.each do |attr, prok|
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
6
22
|
def parse(file_path, options={})
|
7
23
|
CSV.foreach(file_path, options) do |csv|
|
24
|
+
obj = @model.new
|
25
|
+
coerce csv, obj
|
8
26
|
yield csv
|
9
27
|
end
|
10
28
|
end
|
29
|
+
|
30
|
+
def register_model(model)
|
31
|
+
self.model = model
|
32
|
+
end
|
33
|
+
|
34
|
+
def match(attribute, prok)
|
35
|
+
@attribute_matrix[attribute.to_sym] = prok
|
36
|
+
end
|
11
37
|
end
|
12
38
|
end
|
13
39
|
|
14
40
|
module Model
|
15
41
|
class Base
|
42
|
+
|
43
|
+
def attributes
|
44
|
+
attributes_hash = Hash.new
|
45
|
+
self.instance_variables.each do |attr|
|
46
|
+
attributes_hash.store(attr[1..-1].to_sym, instance_eval(attr.to_s))
|
47
|
+
end
|
48
|
+
attributes_hash
|
49
|
+
end
|
50
|
+
|
51
|
+
def format
|
52
|
+
end
|
53
|
+
|
54
|
+
def formatted_attributes
|
55
|
+
attr_hash = attributes
|
56
|
+
attr_hash.each do |k,v|
|
57
|
+
begin
|
58
|
+
attr_hash[k] = send("format_#{k}".to_sym, v)
|
59
|
+
rescue NoMethodError => e
|
60
|
+
# No formatter defined, use passed value as formatted value
|
61
|
+
attr_hash[k] = v.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
attr_hash
|
66
|
+
end
|
16
67
|
end
|
17
68
|
end
|
18
69
|
|
@@ -22,11 +73,20 @@ module Pipeline
|
|
22
73
|
end
|
23
74
|
|
24
75
|
class Base
|
25
|
-
attr_accessor :
|
76
|
+
attr_accessor :parser, :importer
|
77
|
+
|
78
|
+
def initialize
|
79
|
+
@parser = Pipeline::Parser::Base
|
80
|
+
@importer = Pipeline::Importer::Base
|
81
|
+
end
|
26
82
|
|
27
83
|
def parse *args
|
28
84
|
parser.parse *args
|
29
85
|
end
|
30
86
|
|
87
|
+
def import *args
|
88
|
+
importer.import *args
|
89
|
+
end
|
90
|
+
|
31
91
|
end
|
32
92
|
end
|
data/lib/etl-pipeline/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class TestModel < Pipeline::Model::Base
|
3
|
+
attr_accessor :var
|
4
|
+
|
5
|
+
def format_var(var)
|
6
|
+
case var
|
7
|
+
when 'A'
|
8
|
+
return 'B'
|
9
|
+
when 'Y'
|
10
|
+
return 'Z'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Pipeline::Model::Base do
|
16
|
+
before :each do
|
17
|
+
@test_model = TestModel.new
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#attributes' do
|
21
|
+
it 'returns a hash version of the model' do
|
22
|
+
expect(@test_model.attributes).to be_instance_of Hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#formatted_attributes' do
|
27
|
+
before :each do
|
28
|
+
@test_model.var = 'A'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'iterates over its own attributes and returns a formatted attributes hash' do
|
32
|
+
expect(@test_model.formatted_attributes).to be_instance_of Hash
|
33
|
+
expect(@test_model.var).to eq('A')
|
34
|
+
expect(@test_model.formatted_attributes[:var]).to eq('B')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -3,11 +3,15 @@ class TestPipeline < Pipeline::Base
|
|
3
3
|
end
|
4
4
|
|
5
5
|
describe Pipeline do
|
6
|
-
|
7
6
|
it 'has a version number' do
|
8
7
|
expect(Pipeline::VERSION).not_to be_nil
|
9
8
|
expect(Pipeline::VERSION).to be_instance_of String
|
10
9
|
end
|
10
|
+
describe '#new' do
|
11
|
+
it 'returns a new instance of Pipeline' do
|
12
|
+
expect(TestPipeline.new).to be_instance_of TestPipeline
|
13
|
+
end
|
14
|
+
end
|
11
15
|
|
12
16
|
|
13
17
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etl-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elijah Christensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -182,9 +182,10 @@ files:
|
|
182
182
|
- Rakefile
|
183
183
|
- etl-pipeline.gemspec
|
184
184
|
- lib/etl-pipeline.rb
|
185
|
-
- lib/etl-pipeline/csv_parser.rb
|
186
185
|
- lib/etl-pipeline/version.rb
|
187
|
-
- spec/
|
186
|
+
- spec/csv_parser_spec.rb
|
187
|
+
- spec/model_base_spec.rb
|
188
|
+
- spec/pipeline_spec.rb
|
188
189
|
- spec/spec_helper.rb
|
189
190
|
homepage: ''
|
190
191
|
licenses:
|
@@ -211,5 +212,7 @@ signing_key:
|
|
211
212
|
specification_version: 4
|
212
213
|
summary: Pipeline is a modular specimen migration toolkit.
|
213
214
|
test_files:
|
214
|
-
- spec/
|
215
|
+
- spec/csv_parser_spec.rb
|
216
|
+
- spec/model_base_spec.rb
|
217
|
+
- spec/pipeline_spec.rb
|
215
218
|
- spec/spec_helper.rb
|