Class: Gyoku::Array
- Inherits:
-
Object
- Object
- Gyoku::Array
- Defined in:
- lib/gyoku/array.rb
Class Method Summary collapse
-
.to_xml(array, key, escape_xml = true, attributes = {}, options = {}) ⇒ Object
Translates a given
array
to 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
.
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 = {}, = {}) self_closing = .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, ) } when NilClass then xml.tag!(key, "xsi:nil" => "true") else xml.tag!(key, attrs) { xml << XMLValue.create(item, escape_xml) } end end end end |