dagger 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dagger/ox_extension.rb +20 -0
- data/lib/dagger/parsers.rb +1 -0
- data/lib/dagger/version.rb +2 -2
- data/test/parsers_spec.rb +24 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63816a0d187903c137ee41f877ef6f1297c0fc40
|
4
|
+
data.tar.gz: 69a54ec7a10a4cd1482aa809bb50668b973c7867
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 450539509f84b2620985500067745ad0bfb4ebdf1268e468671405bf55ad825c0a1662c62420222498f5cb7a7a827f9e6320cbcd1fa90fc70b732a0cf219401e
|
7
|
+
data.tar.gz: 8340ddc5cf34eb6c4c94f3abb381b76483de5560e3746cb06590f2b9983795dea5e381f1d00ad6f6cb618f834083eb070b9da9183f3b68476edf6522cbe9b3ac
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ox'
|
2
|
+
|
3
|
+
XMLNode = Struct.new(:name, :text, :attributes, :children) do
|
4
|
+
def [](key)
|
5
|
+
children.select { |node| node.name.to_s == key.to_s }.first
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Ox::Document
|
10
|
+
def to_hash
|
11
|
+
nodes.first.to_hash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Ox::Element
|
16
|
+
def to_hash
|
17
|
+
children = nodes.map { |n| n.class == self.class ? n.to_hash : nil }.compact
|
18
|
+
XMLNode.new(value, text, attributes, children)
|
19
|
+
end
|
20
|
+
end
|
data/lib/dagger/parsers.rb
CHANGED
data/lib/dagger/version.rb
CHANGED
data/test/parsers_spec.rb
CHANGED
@@ -67,6 +67,7 @@ describe 'Parsers' do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
describe 'XML' do
|
70
|
+
|
70
71
|
before do
|
71
72
|
allow(fake_resp).to receive(:content_type).and_return('text/xml')
|
72
73
|
end
|
@@ -104,5 +105,28 @@ describe 'Parsers' do
|
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
108
|
+
|
109
|
+
describe 'XMLNode extension' do
|
110
|
+
|
111
|
+
xml = %(
|
112
|
+
<xml>
|
113
|
+
<foo attr="bar">test</foo>
|
114
|
+
<nested>
|
115
|
+
<item>
|
116
|
+
<title attr="downcased">foobar</title>
|
117
|
+
</item>
|
118
|
+
</nested>
|
119
|
+
</xml>
|
120
|
+
)
|
121
|
+
|
122
|
+
it 'works' do
|
123
|
+
doc = Ox.parse(xml)
|
124
|
+
obj = doc.to_hash
|
125
|
+
|
126
|
+
expect(obj[:nested][:item][:title].text).to eql('foobar')
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
107
131
|
end
|
108
132
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- bin/dagger
|
110
110
|
- dagger.gemspec
|
111
111
|
- lib/dagger.rb
|
112
|
+
- lib/dagger/ox_extension.rb
|
112
113
|
- lib/dagger/parsers.rb
|
113
114
|
- lib/dagger/response.rb
|
114
115
|
- lib/dagger/version.rb
|