Class: Array

Inherits:
Object show all
Defined in:
lib/base/helpers/support.xml.rb,
lib/base/helpers/support.rb

Overview

— Array —

Instance Method Summary collapse

Instance Method Details

#_stringify_keysObject

Stringifies keys on all the hash items.



165
166
167
168
169
# File 'lib/base/helpers/support.rb', line 165

def _stringify_keys
  map do |item|
    item.respond_to?(:_stringify_keys) ? item._stringify_keys : item
  end
end

#_symbolize_keysObject

Stringifies keys on all the hash items.



157
158
159
160
161
# File 'lib/base/helpers/support.rb', line 157

def _symbolize_keys
  map do |item|
    item.respond_to?(:_symbolize_keys) ? item._symbolize_keys : item
  end
end

#_to_xml(opts = {}) ⇒ String

Returns an XML-representation if the array object.

Examples:

[1,2,3,4]._to_xml #=>
  '<item>1</item><item>2</item><item>3</item><item>4</item>'
[1,2,3,4]._to_xml(:crlf => "\n") #=>
   <item>1</item>
   <item>2</item>
   <item>3</item>
   <item>4</item>
[1,2,[3,4,[5]]]._to_xml(:indent => '  ', :tag => 'hoho') #=>
   <hoho>1</hoho>
   <hoho>2</hoho>
   <hoho>
     <item>3</item>
     <item>4</item>
     <item>
       <item>5</item>
     </item>
   </hoho>

Parameters:

  • opts (Hash) (defaults to: {})

    A set of options.

Options Hash (opts):

  • :escape (Boolean)

    The flag.

  • :tag (String)

    The tag every array item is to be wrapped with (‘<item>’ by default)

Returns:



145
146
147
148
149
# File 'lib/base/helpers/support.xml.rb', line 145

def _to_xml(opts={})
  opts = _xml_get_opts(opts)
  tag  = opts.delete(:tag) || 'item'
  { tag => self }._to_xml(opts)
end