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 CHANGED
@@ -1 +1 @@
1
- 0.2.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
- elsif node.elements.size == 0
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{partigirb}
5
- s.version = "0.2.2"
5
+ s.version = "0.2.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alvaro Bautista", "Fernando Blat"]
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: partigi-partigirb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alvaro Bautista