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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbe26ea3b30c0f151159b8bdc9a48acea0f24b37
4
- data.tar.gz: 601cbcea87df3a8c13222859b4cf1250899d5354
3
+ metadata.gz: 63816a0d187903c137ee41f877ef6f1297c0fc40
4
+ data.tar.gz: 69a54ec7a10a4cd1482aa809bb50668b973c7867
5
5
  SHA512:
6
- metadata.gz: a92365c53c1ebe65027ad80b1ddfdfffdbcca9b74fb30e43549b8ee42795351bad334619105e9d032f99b071c7ae3f52fc26b226ac75b0710352e2b7ce18264d
7
- data.tar.gz: cfe2b4d7002a0897146b26e1caf998c9d57c10ca8b56c42b2a6e1dd18153c48c8bf816b38eb6091b4bb3106c82f67db327006d659c39efc5e3bb53d5ff563f03
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
@@ -1,5 +1,6 @@
1
1
  require 'oj'
2
2
  require 'ox'
3
+ require 'dagger/ox_extension'
3
4
 
4
5
  class Parsers
5
6
 
@@ -1,7 +1,7 @@
1
1
  module Dagger
2
2
  MAJOR = 0
3
- MINOR = 4
4
- PATCH = 2
3
+ MINOR = 5
4
+ PATCH = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
@@ -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.2
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