partigi-partigirb 0.2.2 → 0.2.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.
- data/VERSION +1 -1
- data/lib/partigirb/handlers/xml_handler.rb +14 -3
- data/partigirb.gemspec +1 -1
- data/test/xml_handler_test.rb +21 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -11,9 +11,9 @@ module Partigirb
|
|
11
11
|
def load_recursive(node)
|
12
12
|
if array_node?(node)
|
13
13
|
node.elements.map {|e| load_recursive(e)}
|
14
|
-
elsif node.elements.size > 0
|
15
|
-
build_struct(node)
|
16
|
-
|
14
|
+
elsif node.elements.size > 0 || node.attributes.size > 0
|
15
|
+
build_struct(node)
|
16
|
+
else
|
17
17
|
value = node.text
|
18
18
|
fixnum?(value) ? value.to_i : value
|
19
19
|
end
|
@@ -21,6 +21,17 @@ module Partigirb
|
|
21
21
|
|
22
22
|
def build_struct(node)
|
23
23
|
ts = PartigiStruct.new
|
24
|
+
|
25
|
+
node.attributes.each do |a,v|
|
26
|
+
# In case the Struct object already responds to a method
|
27
|
+
# with same name like type case
|
28
|
+
if ts.respond_to?(a)
|
29
|
+
ts.send("_#{a}=",v)
|
30
|
+
else
|
31
|
+
ts.send("#{a}=", v) unless a =~ /^xmlns/
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
24
35
|
node.elements.each do |e|
|
25
36
|
property = ""
|
26
37
|
|
data/partigirb.gemspec
CHANGED
data/test/xml_handler_test.rb
CHANGED
@@ -62,4 +62,25 @@ class XMLHandlerTest < Test::Unit::TestCase
|
|
62
62
|
assert_equal 123, res.nameSpace_id
|
63
63
|
assert_equal 'Bob', res.nameSpace_name
|
64
64
|
end
|
65
|
+
|
66
|
+
should "extract attributes from nodes" do
|
67
|
+
xmls = build_xml_string do |xml|
|
68
|
+
xml.instruct!
|
69
|
+
xml.user do
|
70
|
+
xml.id 123
|
71
|
+
xml.name 'Bob'
|
72
|
+
xml.link({:rel => 'alternate', :href => 'http://www.pointing-to-something.com', :type => 'text/html'})
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
res = @handler.decode_response(xmls)
|
77
|
+
assert res.is_a?(Partigirb::PartigiStruct)
|
78
|
+
assert_equal 123, res.id
|
79
|
+
assert_equal 'Bob', res.name
|
80
|
+
|
81
|
+
assert res.link.is_a?(Partigirb::PartigiStruct)
|
82
|
+
assert_equal 'alternate', res.link.rel
|
83
|
+
assert_equal 'text/html', res.link._type
|
84
|
+
assert_equal 'http://www.pointing-to-something.com', res.link.href
|
85
|
+
end
|
65
86
|
end
|