Class: Gyoku::Hash
- Inherits:
-
Object
- Object
- Gyoku::Hash
- Defined in:
- lib/gyoku/hash.rb
Class Method Summary collapse
-
.to_xml(hash, options = {}) ⇒ Object
Translates a given
hash
withoptions
to XML.
Class Method Details
.to_xml(hash, options = {}) ⇒ Object
Translates a given hash
with options
to XML.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gyoku/hash.rb', line 11 def self.to_xml(hash, = {}) iterate_with_xml hash do |xml, key, value, attributes| self_closing = key.to_s[-1, 1] == "/" escape_xml = key.to_s[-1, 1] != "!" xml_key = XMLKey.create key, case when ::Array === value then xml << Array.to_xml(value, xml_key, escape_xml, attributes, ) when ::Hash === value then xml.tag!(xml_key, attributes) { xml << Hash.to_xml(value, ) } when self_closing then xml.tag!(xml_key, attributes) when NilClass === value then xml.tag!(xml_key, "xsi:nil" => "true") else xml.tag!(xml_key, attributes) { xml << XMLValue.create(value, escape_xml) } end end end |