forked from lovehandle/agent_cooper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Response#to_hash bug lovehandle#1
- Loading branch information
Ryan Closner
committed
Apr 6, 2012
1 parent
4c2a15a
commit 7395a2e
Showing
5 changed files
with
37 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ def body | |
|
||
# @api public | ||
def to_hash | ||
AgentCooper::Builder.from_xml(xml) | ||
xml.to_hash | ||
end | ||
|
||
# @api public | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Nokogiri::XML | ||
|
||
class Document | ||
|
||
def to_hash | ||
self.root.element? ? self.root.to_hash : {self.root.name => self.root.text} | ||
end | ||
|
||
end | ||
|
||
class Element | ||
|
||
def to_hash | ||
{ self.name => self.collect_attributes } | ||
end | ||
|
||
def collect_attributes | ||
({}).tap do |hash| | ||
self.children.each do |child| | ||
next if child.text? | ||
if child.element? | ||
if child.children.length > 1 | ||
hash[child.name] = child.collect_attributes | ||
else | ||
hash[child.name] = child.text.strip | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters