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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a32f86bc2140f39a18bd20b0c53bcbb45a9f34e9
4
- data.tar.gz: 00d35b0e2087df6c1d6bd9fdaaf55d9a9c149a5f
3
+ metadata.gz: 13a331caaeeed805384451146acaa5d9423db764
4
+ data.tar.gz: b0efdfd06adafa8ab7fa27316c3e0beef410318e
5
5
  SHA512:
6
- metadata.gz: c5e27d470fb3803f3a28e782aff7566eab6b839e357115191989fa8514b0f926bc620edf286dd05d1d6c68b5748071b012df96157d9713e25ee79bf3eebc8834
7
- data.tar.gz: 430e84bb49d454e3e844b820dbd6549112c5c76b3968e5ecd77fb7cd3d46679c7b59e9fb5185fc46b586aa1aef102c54f1dd0a1c0abd9a4c72384674ab667490
6
+ metadata.gz: 970c056f28a680aeadea3c7d1d61e654896cf9d8239c5e826b5219d24222c70a621bf5889380ec47dbc8e839b8478f7d0430616de53468a1536df9a2e994954a
7
+ data.tar.gz: f753ed345ccc4f30586a1037bd443cee8bfa588e16612a80e953097236e66bab43e535f7e41ba2bebb425aee4715875aa1061a7bc58f34cecb7b4e77c923f72d
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.0
5
- before_install: gem install bundler -v 1.13.1
4
+ - 2.4.0
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 -- superceeds `xpath` or `csv_header` values
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
@@ -36,10 +36,10 @@ module Eatr
36
36
  private
37
37
 
38
38
  def value_at(row, field)
39
- if field.value
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
@@ -1,3 +1,3 @@
1
1
  module Eatr
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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
- file = File.open(xml_document_path)
29
+ doc = File.open(xml_document_path, &parse_document)
26
30
  else
27
- file = StringIO.new(xml_document_path)
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.value
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 = Nokogiri::XML(File.open(@xml_path)) do |config|
10
- config.strict.nonet
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.2
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-01-16 00:00:00.000000000 Z
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:
@@ -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