smacks-apricoteatsgorilla 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/apricoteatsgorilla.rb +14 -9
- data/tests/apricoteatsgorilla_test.rb +1 -1
- metadata +1 -1
data/lib/apricoteatsgorilla.rb
CHANGED
@@ -79,6 +79,7 @@ class ApricotEatsGorilla
|
|
79
79
|
end
|
80
80
|
|
81
81
|
key = remove_namespace(key)
|
82
|
+
key = to_snake_case(key)
|
82
83
|
current = this_node[key]
|
83
84
|
case current
|
84
85
|
when Array
|
@@ -117,25 +118,29 @@ class ApricotEatsGorilla
|
|
117
118
|
|
118
119
|
# Returns a sorted version of a given Hash in case :sort_keys is enabled.
|
119
120
|
def opt_order(hash)
|
120
|
-
|
121
|
-
|
122
|
-
else
|
123
|
-
hash
|
124
|
-
end
|
121
|
+
return hash unless sort_keys
|
122
|
+
hash.sort_by { |kv| kv.first }
|
125
123
|
end
|
126
124
|
|
127
|
-
#
|
125
|
+
# Removes line breaks and whitespace between XML tags.
|
128
126
|
def clean_xml(xml)
|
129
127
|
xml = xml.gsub(/\n+/, "")
|
130
|
-
xml
|
128
|
+
xml.gsub(/(>)\s*(<)/, '\1\2')
|
131
129
|
end
|
132
130
|
|
133
|
-
#
|
131
|
+
# Removes namespaces from XML tags.
|
134
132
|
def remove_namespace(tag)
|
135
133
|
tag.sub(/.+:(.+)/, '\1')
|
136
134
|
end
|
137
135
|
|
138
|
-
#
|
136
|
+
# Converts CamelCase and lowerCamelCase to snake_case.
|
137
|
+
def to_snake_case(string)
|
138
|
+
string = string.gsub(/[A-Z]+/, '\1_\0').downcase
|
139
|
+
string = string[1, string.length-1] if string[0, 1] == "_"
|
140
|
+
string
|
141
|
+
end
|
142
|
+
|
143
|
+
# Converts "true" and "false" strings to boolean values.
|
139
144
|
# Returns the original string in case it doesn't match "true" or "false".
|
140
145
|
def booleanize(string)
|
141
146
|
return true if string == "true"
|
@@ -22,7 +22,7 @@ class ApricotEatsGorillaTest < Test::Unit::TestCase
|
|
22
22
|
</ns2:authenticateResponse>
|
23
23
|
</soap:Body>
|
24
24
|
</soap:Envelope>'
|
25
|
-
expected = { '
|
25
|
+
expected = { 'auth_value' => { 'token' => 'secret', 'client' => 'example' } }
|
26
26
|
|
27
27
|
result = ApricotEatsGorilla.xml_to_hash(xml, '//return')
|
28
28
|
assert_equal expected, result
|