eatr 0.1.2 → 0.1.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/.travis.yml +1 -2
- data/README.md +2 -3
- data/lib/eatr/csv/document.rb +3 -3
- data/lib/eatr/schema.rb +5 -1
- data/lib/eatr/version.rb +1 -1
- data/lib/eatr/xml/document.rb +11 -8
- data/lib/eatr/xml/schema_generator.rb +4 -2
- metadata +2 -4
- data/lib/eatr/pipeline_spec.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13a331caaeeed805384451146acaa5d9423db764
|
4
|
+
data.tar.gz: b0efdfd06adafa8ab7fa27316c3e0beef410318e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 970c056f28a680aeadea3c7d1d61e654896cf9d8239c5e826b5219d24222c70a621bf5889380ec47dbc8e839b8478f7d0430616de53468a1536df9a2e994954a
|
7
|
+
data.tar.gz: f753ed345ccc4f30586a1037bd443cee8bfa588e16612a80e953097236e66bab43e535f7e41ba2bebb425aee4715875aa1061a7bc58f34cecb7b4e77c923f72d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -125,9 +125,8 @@ Here is an example from the test suite of using this XML and schema defintion:
|
|
125
125
|
- `required`
|
126
126
|
- optional -- defaults to `true`
|
127
127
|
- If a node cannot be found at the given `xpath`, an `Eatr::NodeNotFound` error is raised.
|
128
|
-
- `value`
|
129
|
-
- optional --
|
130
|
-
- If set, this value will be used as the attribute's value
|
128
|
+
- `value` or `default`
|
129
|
+
- optional -- used if a value at `xpath` or `csv_header` isn't found.
|
131
130
|
- `strptime`
|
132
131
|
- optional -- only applicable if `type` is `timestamp`
|
133
132
|
- Format string used to parse the string into a `DateTime` object
|
data/lib/eatr/csv/document.rb
CHANGED
@@ -36,10 +36,10 @@ module Eatr
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def value_at(row, field)
|
39
|
-
if field.
|
40
|
-
field.value
|
41
|
-
elsif text = row[field.csv_header]
|
39
|
+
if text = row[field.csv_header]
|
42
40
|
parse_value(field, text)
|
41
|
+
elsif field.value
|
42
|
+
parse_value(field, field.value)
|
43
43
|
elsif field.required?
|
44
44
|
raise ValueNotFound, "Unable to find '#{field.name}' with header '#{field.csv_header}'"
|
45
45
|
end
|
data/lib/eatr/schema.rb
CHANGED
@@ -11,7 +11,6 @@ module Eatr
|
|
11
11
|
xpath
|
12
12
|
csv_header
|
13
13
|
strptime
|
14
|
-
value
|
15
14
|
max_length
|
16
15
|
length
|
17
16
|
belongs_to_one
|
@@ -37,6 +36,11 @@ module Eatr
|
|
37
36
|
def children
|
38
37
|
Array[*@field_attributes['children']].map { |f| Field.new(f) }
|
39
38
|
end
|
39
|
+
|
40
|
+
def value
|
41
|
+
@field_attributes['value'] ||
|
42
|
+
@field_attributes['default']
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
def initialize(schema_hash)
|
data/lib/eatr/version.rb
CHANGED
data/lib/eatr/xml/document.rb
CHANGED
@@ -21,15 +21,16 @@ module Eatr
|
|
21
21
|
def parse(xml_document_path)
|
22
22
|
@namespaces = {}
|
23
23
|
|
24
|
+
parse_document = ->(f) do
|
25
|
+
Nokogiri::XML(f) { |config| config.strict.nonet }
|
26
|
+
end
|
27
|
+
|
24
28
|
if File.exists?(xml_document_path)
|
25
|
-
|
29
|
+
doc = File.open(xml_document_path, &parse_document)
|
26
30
|
else
|
27
|
-
|
31
|
+
doc = StringIO.open(xml_document_path, &parse_document)
|
28
32
|
end
|
29
33
|
|
30
|
-
doc = Nokogiri::XML(file) do |config|
|
31
|
-
config.strict.nonet
|
32
|
-
end
|
33
34
|
|
34
35
|
if @schema.remove_namespaces?
|
35
36
|
doc.remove_namespaces!
|
@@ -78,14 +79,16 @@ module Eatr
|
|
78
79
|
end
|
79
80
|
|
80
81
|
def value_at(doc, field)
|
81
|
-
if field.
|
82
|
-
field.value
|
83
|
-
elsif field.xpath
|
82
|
+
if field.xpath
|
84
83
|
if node = doc.at_xpath(field.xpath, @namespaces)
|
85
84
|
parse_value(field, node.content)
|
85
|
+
elsif field.value
|
86
|
+
parse_value(field, field.value)
|
86
87
|
elsif field.required?
|
87
88
|
raise NodeNotFound, "Unable to find '#{field.name}' using xpath '#{field.xpath}'"
|
88
89
|
end
|
90
|
+
elsif field.value
|
91
|
+
field.value
|
89
92
|
end
|
90
93
|
end
|
91
94
|
end
|
@@ -6,8 +6,10 @@ module Eatr
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def schema(starting_point)
|
9
|
-
doc =
|
10
|
-
config
|
9
|
+
doc = File.open(@xml_path) do |f|
|
10
|
+
Nokogiri::XML(f) do |config|
|
11
|
+
config.strict.nonet
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
doc.remove_namespaces!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eatr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greggory Rothmeier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- lib/eatr/dot_template.dot
|
106
106
|
- lib/eatr/parse_value.rb
|
107
107
|
- lib/eatr/pipeline.rb
|
108
|
-
- lib/eatr/pipeline_spec.rb
|
109
108
|
- lib/eatr/schema.rb
|
110
109
|
- lib/eatr/sql/table_generator.rb
|
111
110
|
- lib/eatr/transformation/add_date_id.rb
|
@@ -139,4 +138,3 @@ signing_key:
|
|
139
138
|
specification_version: 4
|
140
139
|
summary: Configuration-based document parsing and transformation framework.
|
141
140
|
test_files: []
|
142
|
-
has_rdoc:
|
data/lib/eatr/pipeline_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require './lib/eatr/pipeline'
|
3
|
-
|
4
|
-
describe Eatr::Pipeline do
|
5
|
-
it 'performs each action on an object' do
|
6
|
-
pipeline = described_class.new([
|
7
|
-
->(str) { str.upcase },
|
8
|
-
->(str) { str[1..3] },
|
9
|
-
])
|
10
|
-
|
11
|
-
expect(pipeline.call("hello")).to eq("ELL")
|
12
|
-
end
|
13
|
-
end
|