smacks-apricoteatsgorilla 0.2.7 → 0.2.8

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.
@@ -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
- if sort_keys
121
- hash.sort_by{ |kv| kv.first }
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
- # Helper to remove line breaks and whitespace between XML tags.
125
+ # Removes line breaks and whitespace between XML tags.
128
126
  def clean_xml(xml)
129
127
  xml = xml.gsub(/\n+/, "")
130
- xml = xml.gsub(/(>)\s*(<)/, '\1\2')
128
+ xml.gsub(/(>)\s*(<)/, '\1\2')
131
129
  end
132
130
 
133
- # Helper to remove namespaces from XML tags.
131
+ # Removes namespaces from XML tags.
134
132
  def remove_namespace(tag)
135
133
  tag.sub(/.+:(.+)/, '\1')
136
134
  end
137
135
 
138
- # Helper to convert "true" and "false" strings to boolean values.
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 = { 'authValue' => { 'token' => 'secret', 'client' => 'example' } }
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
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.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington