dagger 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/dagger/ox_extension.rb +24 -0
- data/lib/dagger/parsers.rb +3 -1
- data/lib/dagger/version.rb +2 -2
- data/spec/parsers_spec.rb +11 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4bfc1ae0c456b34133f1193441ade9ec29aff0a12c8cd3d5789431095e0b9460
|
4
|
+
data.tar.gz: 4793e4ca427ee9ed39dd93b0b3eb0055023a3fcbacb2e168e1e1dc91c56ae988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd762ea62c7d7a5a10d8c953900c7875aefa4e4b8c983b8b198bdbbf9083d218b8b8aad156d89ae30a457be3f7e0cd51f4dbb0d35ff92bb7ef6032d28e98a302
|
7
|
+
data.tar.gz: 980873071693904349794ca12d5b22ad791ba52ac658ce8225da61fc94faaa4e8a4529c30fbb6cd6be3945d6a83cc31fb4bb5288f957f8d8a309646712b592be
|
data/lib/dagger/ox_extension.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'ox'
|
2
2
|
|
3
3
|
XMLNode = Struct.new(:name, :text, :attributes, :children) do
|
4
|
+
|
5
|
+
alias_method :to_s, :text
|
6
|
+
alias_method :value, :text
|
7
|
+
|
8
|
+
def to_hash
|
9
|
+
self # for backwards compat
|
10
|
+
end
|
11
|
+
|
4
12
|
# this lets us traverse an parsed object like this:
|
5
13
|
# doc[:child][:grandchild].value
|
6
14
|
def [](key)
|
@@ -8,6 +16,22 @@ XMLNode = Struct.new(:name, :text, :attributes, :children) do
|
|
8
16
|
found.empty? ? nil : found.size == 1 ? found.first : found
|
9
17
|
end
|
10
18
|
|
19
|
+
def dig(*paths)
|
20
|
+
list = Array(paths).flatten
|
21
|
+
res = list.reduce([self]) do |parents, key|
|
22
|
+
|
23
|
+
if parents
|
24
|
+
found = parents.map do |parent|
|
25
|
+
parent.children.select { |node| node.name.to_s == key.to_s }
|
26
|
+
end.flatten
|
27
|
+
|
28
|
+
found.any? ? found : nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
res.nil? || res.empty? ? nil : res.size == 1 ? res.first : res
|
33
|
+
end
|
34
|
+
|
11
35
|
# returns first matching node
|
12
36
|
def first(key)
|
13
37
|
if found = self[key]
|
data/lib/dagger/parsers.rb
CHANGED
data/lib/dagger/version.rb
CHANGED
data/spec/parsers_spec.rb
CHANGED
@@ -94,18 +94,23 @@ describe 'Parsers' do
|
|
94
94
|
|
95
95
|
describe 'valid data' do
|
96
96
|
before do
|
97
|
-
allow(fake_resp).to receive(:body).and_return('<xml><foo>123</foo></xml>')
|
97
|
+
allow(fake_resp).to receive(:body).and_return('<xml><foo>123</foo><bar><test>456</test></bar></xml>')
|
98
98
|
end
|
99
99
|
|
100
|
-
it 'returns
|
100
|
+
it 'returns XMLNode obj' do
|
101
101
|
res = send_request.data
|
102
|
-
expect(res).to be_a(
|
103
|
-
expect(res.
|
104
|
-
expect(res
|
102
|
+
expect(res).to be_a(XMLNode)
|
103
|
+
expect(res.to_hash).to eql(res)
|
104
|
+
expect(res['foo']).to be_a(XMLNode)
|
105
|
+
expect(res['foo'].text).to eql('123')
|
106
|
+
|
107
|
+
# test dig behaviour
|
108
|
+
expect(res.dig('xxx', 'test', '111')).to be(nil)
|
109
|
+
expect(res.dig('bar', 'test')).to be_a(XMLNode)
|
110
|
+
expect(res.dig('bar', 'test').to_s).to eql('456')
|
105
111
|
end
|
106
112
|
end
|
107
113
|
|
108
|
-
|
109
114
|
describe 'XMLNode extension' do
|
110
115
|
|
111
116
|
xml = %(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: 1.3.6
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project: dagger
|
138
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.7.3
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Simplified Net::HTTP wrapper.
|