Parent

Methods

Class/Module Index [+]

Quicksearch

Gyoku::Hash

Public Class Methods

to_xml(hash, options = {}) click to toggle source

Translates a given hash with options to XML.

# File lib/gyoku/hash.rb, line 11
def self.to_xml(hash, options = {})
  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, options

    case
      when ::Array === value  then xml << Array.to_xml(value, xml_key, escape_xml, attributes, options)
      when ::Hash === value   then xml.tag!(xml_key, attributes) { xml << Hash.to_xml(value, options) }
      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

[Validate]

Generated with the Darkfish Rdoc Generator 2.