Method: Jamf::Utility#hash_to_rexml_array

Defined in:
lib/jamf/utility.rb

#hash_to_rexml_array(hash) ⇒ Array<REXML::Element>

Given a simple Hash, convert it to an array of REXML Elements such that each key becomes an element, and its value becomes the text content of that element

Examples:

my_hash = {:foo => "bar", :baz => :morefoo}
xml = JSS.hash_to_rexml_array(my_hash)
xml.each{|x| puts x }

<foo>bar</foo>
<baz>morefoo</baz>

Parameters:

  • hash (Hash{#to_s => #to_s})

    the Hash to convert

Returns:

  • (Array<REXML::Element>)

    the Array of REXML elements.

Raises:



491
492
493
494
495
496
497
498
499
500
501
# File 'lib/jamf/utility.rb', line 491

def hash_to_rexml_array(hash)
  raise InvalidDataError, 'Arg. must be a Hash.' unless hash.is_a? Hash

  ary = []
  hash.each_pair do |k, v|
    el = REXML::Element.new k.to_s
    el.text = v
    ary << el
  end
  ary
end