Class: Gyoku::Array

Inherits:
Object
  • Object
show all
Defined in:
lib/gyoku/array.rb

Class Method Summary collapse

Class Method Details

.to_xml(array, key, escape_xml = true, attributes = {}, options = {}) ⇒ Object

Translates a given array to XML. Accepts the XML key to add the elements to, whether to escape_xml and an optional Hash of attributes.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gyoku/array.rb', line 11

def self.to_xml(array, key, escape_xml = true, attributes = {}, options = {})
  self_closing = options.delete(:self_closing)
  iterate_with_xml array, attributes do |xml, item, attrs, index|
    if self_closing
      xml.tag!(key, attrs)

    else
      case item
        when ::Hash       then xml.tag!(key, attrs) { xml << Hash.to_xml(item, options) }
        when NilClass     then xml.tag!(key, "xsi:nil" => "true")
        else              xml.tag!(key, attrs) { xml << XMLValue.create(item, escape_xml) }
      end
    end
  end
end