smacks-apricoteatsgorilla 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -74,18 +74,11 @@ class ApricotEatsGorilla
74
74
  # # => { :lots_of => "Gorillas" }
75
75
  def xml_to_hash(xml, root_node = nil)
76
76
  doc = Hpricot.XML clean_xml(xml)
77
- root = root_node ? doc.search(root_node) : doc.root
77
+ root = root_node ? doc.at(root_node) : doc.root
78
78
 
79
- return nil if root.nil?
80
- # root is an Hpricot::Elements object
81
- if root.respond_to?(:count)
82
- # root is an Hpricot::Elements object with only one element
83
- return root.entries.map { |e| xml_node_to_hash(e) } if root.count > 1
84
- root = root.entries.first
85
- if root.children.size == 1 && root.children.first.text?
86
- # root contains text only
87
- return root.children.first.to_s
88
- end
79
+ return nil if root.nil? # root_node not found
80
+ if root.children.size == 1 && root.children.first.kind_of?(Hpricot::Text)
81
+ return root.children.first.to_s # text-only value
89
82
  end
90
83
  xml_node_to_hash(root)
91
84
  end
@@ -73,17 +73,6 @@ class XmlToHashTest < Test::Unit::TestCase
73
73
  end
74
74
  end
75
75
 
76
- context "with XML containing multiple custom root nodes" do
77
- should "return an Array containing the multiple root nodes" do
78
- xml = '<root><return><id>3</id><name>Julia</name></return>' <<
79
- '<return><id>5</id><name>Gorilla</name></return></root>'
80
- expected = [{ :id => "3", :name => "Julia"}, { :id => "5", :name => "Gorilla"}]
81
-
82
- result = ApricotEatsGorilla.xml_to_hash(xml, "//return")
83
- assert_equal expected, result
84
- end
85
- end
86
-
87
76
  context "with XML containing lowerCamelCase nodes" do
88
77
  should "convert lowerCamelCase nodes to snake_case" do
89
78
  xml = "<contact><firstName>Jungle</firstName><lastName>Julia</lastName></contact>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smacks-apricoteatsgorilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington