smacks-apricoteatsgorilla 0.2.0 → 0.2.1
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/README.rdoc +3 -3
- data/lib/apricoteatsgorilla.rb +3 -3
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Apricot eats Gorilla translates between XML documents and Ruby hashes.
|
|
4
4
|
It's based on CobraVsMongoose but uses Hpricot instead of REXML to parse
|
5
5
|
XML and it also doesn't follow the BadgerFish convention.
|
6
6
|
|
7
|
-
|
7
|
+
Its initial purpose was to convert SOAP response messages to Ruby hashes,
|
8
8
|
but it quickly evolved into a more general translation tool.
|
9
9
|
|
10
10
|
== Install
|
@@ -36,13 +36,13 @@ Let's assume you receive the following SOAP response:
|
|
36
36
|
</soap:Body>
|
37
37
|
</soap:Envelope>
|
38
38
|
|
39
|
-
Just pass in the raw XML string
|
39
|
+
Just pass in the raw XML string:
|
40
40
|
|
41
41
|
require "rubygems"
|
42
42
|
require "apricoteatsgorilla
|
43
43
|
hash = ApricotEatsGorilla.xml_to_hash(xml, "//return")
|
44
44
|
|
45
|
-
And it gets converted into a nice little
|
45
|
+
And it gets converted into a nice little Hash:
|
46
46
|
|
47
47
|
"empty" => false,
|
48
48
|
"customer" => {
|
data/lib/apricoteatsgorilla.rb
CHANGED
@@ -6,13 +6,13 @@ require 'hpricot'
|
|
6
6
|
# It's based on CobraVsMongoose but uses Hpricot instead of REXML to parse
|
7
7
|
# XML and it also doesn't follow the BadgerFish convention.
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# Its initial purpose was to convert SOAP response messages to Ruby hashes,
|
10
10
|
# but it quickly evolved into a more general translation tool.
|
11
11
|
class ApricotEatsGorilla
|
12
12
|
|
13
13
|
# Converts XML into a Ruby Hash. Starts parsing at root node by default.
|
14
14
|
# Call with XPath expession (Hpricot search) as second parameter to define
|
15
|
-
# a custom root node. The root node itself
|
15
|
+
# a custom root node. The root node itself will not be included in the Hash.
|
16
16
|
#
|
17
17
|
# E.g.
|
18
18
|
# xml = "<dude><likes>beer</likes><hates>appletini</hates></dude>"
|
@@ -99,7 +99,7 @@ private
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
# Helper to remove line breaks and whitespace between XML
|
102
|
+
# Helper to remove line breaks and whitespace between XML tags.
|
103
103
|
def self.clean_xml(xml)
|
104
104
|
xml = xml.gsub(/\n+/, "")
|
105
105
|
xml = xml.gsub(/(>)\s*(<)/, '\1\2')
|