lib/apricoteatsgorilla/apricoteatsgorilla.rb in rubiii-apricoteatsgorilla-0.5.3 vs lib/apricoteatsgorilla/apricoteatsgorilla.rb in rubiii-apricoteatsgorilla-0.5.4
- old
+ new
@@ -212,16 +212,16 @@
when Array
subvalue.map { |subitem| nested_data_to_xml(subkey, subitem) }.join
when Hash
nested_data_to_xml(subkey, subvalue)
else
- xml_node(subkey) { subvalue.to_s } if subvalue.respond_to? :to_s
+ xml_node(subkey) { map_hash_value(subvalue) } if map_hash_value(subvalue)
end
end.join
end
else
- xml_node(key) { value.to_s } if value.respond_to? :to_s
+ xml_node(key) { map_hash_value(value) } if map_hash_value(value)
end
end
# Returns an XML tag with a given +name+. Accepts a +block+ for tag content.
# Defaults to returning an empty-element tag in case no block was given.
@@ -244,9 +244,20 @@
def map_xml_value(value)
case value
when "true" then true
when "false" then false
else value
+ end
+ end
+
+ # Converts Hash values into valid XML values.
+ def map_hash_value(value)
+ if value.kind_of? DateTime
+ value.strftime("%Y-%m-%dT%H:%M:%S")
+ elsif value.respond_to? :to_s
+ value.to_s
+ else
+ nil
end
end
# Returns a sorted version of a given +hash+ if +sort_keys+ is enabled.
def sort_hash_keys(hash)