smacks-apricoteatsgorilla 0.3.7 → 0.3.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.
Files changed (2) hide show
  1. data/lib/apricoteatsgorilla.rb +21 -12
  2. metadata +1 -1
@@ -56,6 +56,12 @@ class ApricotEatsGorilla
56
56
  # Flag to disable conversion of Hash keys to Symbols.
57
57
  attr_accessor :disable_hash_keys_to_symbol
58
58
 
59
+ # Array of XML nodes to add a namespace to.
60
+ attr_accessor :nodes_to_namespace
61
+
62
+ # The namespace for nodes in :nodes_to_namespace.
63
+ attr_accessor :node_namespace
64
+
59
65
  # Shortcut method for translating between XML Strings and Ruby Hashes.
60
66
  # Delegates to xml_to_hash in case +source+ is of type String or delegates
61
67
  # to hash_to_xml in case +source+ is of type Hash. Returns nil otherwise.
@@ -166,6 +172,18 @@ class ApricotEatsGorilla
166
172
  end
167
173
  end
168
174
 
175
+ # Converts a given +string+ from CamelCase/lowerCamelCase to snake_case.
176
+ def to_snake_case(string)
177
+ string = string.gsub(/[A-Z]+/, '\1_\0').downcase
178
+ string = string[1, string.length-1] if string[0, 1] == "_"
179
+ string
180
+ end
181
+
182
+ # Converts a given +string+ from snake_case to lowerCamelCase.
183
+ def to_lower_camel_case(string)
184
+ string.to_s.gsub(/_(.)/) { $1.upcase }
185
+ end
186
+
169
187
  private
170
188
 
171
189
  # Actual implementation for xml_to_hash. Takes and iterates through a given
@@ -240,6 +258,9 @@ class ApricotEatsGorilla
240
258
  # * +attributes+ - Optional. Hash of attributes for the XML tag.
241
259
  def tag(name, attributes = {})
242
260
  name = to_lower_camel_case(name) unless disable_tag_names_to_lower_camel_case
261
+ if nodes_to_namespace.kind_of? Array
262
+ name = "#{node_namespace}:#{name}" if node_namespace && nodes_to_namespace.include?(name)
263
+ end
243
264
  return "<#{name} />" unless block_given?
244
265
 
245
266
  attr = opt_order(attributes).map { |k, v| %Q( xmlns:#{k}="#{v}") }.to_s
@@ -260,18 +281,6 @@ class ApricotEatsGorilla
260
281
  tag
261
282
  end
262
283
 
263
- # Converts a given +string+ from CamelCase/lowerCamelCase to snake_case.
264
- def to_snake_case(string)
265
- string = string.gsub(/[A-Z]+/, '\1_\0').downcase
266
- string = string[1, string.length-1] if string[0, 1] == "_"
267
- string
268
- end
269
-
270
- # Converts a given +string+ from snake_case to lowerCamelCase.
271
- def to_lower_camel_case(string)
272
- string.to_s.gsub(/_(.)/) { $1.upcase }
273
- end
274
-
275
284
  # Checks to see if a given +string+ matches "true" or "false" and converts
276
285
  # these values to actual Boolean objects. Returns the original string in
277
286
  # case it does not match "true" or "false".
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.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington