Class: Ukoyg::Array
- Inherits:
-
Object
- Object
- Ukoyg::Array
- Defined in:
- lib/ukoyg/array.rb
Constant Summary collapse
- NESTED_ELEMENT_NAME =
"element"
Class Method Summary collapse
-
.to_xml(array, key, escape_xml = true, attributes = {}, options = {}) ⇒ Object
Translates a given
arrayto XML.
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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ukoyg/array.rb', line 13 def self.to_xml(array, key, escape_xml = true, attributes = {}, = {}) self_closing = .delete(:self_closing) unwrap = [:unwrap] || false iterate_with_xml array, key, attributes, do |xml, item, attrs, index| if self_closing xml.tag!(key, attrs) else case item when ::Hash then if unwrap xml << Hash.to_xml(item, ) else xml.tag!(key, attrs) { xml << Hash.to_xml(item, ) } end when ::Array then xml.tag!(key, attrs) { xml << Array.to_xml(item, NESTED_ELEMENT_NAME) } when NilClass then xml.tag!(key, "xsi:nil" => "true") else xml.tag!(key, attrs) { xml << XMLValue.create(item, escape_xml) } end end end end |