class LolSoap::HashBuilder

Turns an XML node into a hash data structure. Works out which elements are supposed to be collections based on the type information.

Attributes

node[R]
type[R]

Public Class Methods

new(node, type) click to toggle source
# File lib/lolsoap/hash_builder.rb, line 7
def initialize(node, type)
  @node = node
  @type = type
end

Public Instance Methods

output() click to toggle source
# File lib/lolsoap/hash_builder.rb, line 12
def output
  if node.first_element_child
    children_hash
  else
    content
  end
end

Private Instance Methods

children_hash() click to toggle source

@private

# File lib/lolsoap/hash_builder.rb, line 23
def children_hash
  hash = {}
  node.element_children.each do |child|
    element = type.element(child.name)
    output  = self.class.new(child, element.type).output
    val     = hash[child.name]

    if output
      if val
        if val.is_a?(Array)
          val << output
        else
          hash[child.name] = [val, output]
        end
      else
        hash[child.name] = element.singular? ? output : [output]
      end
    else
      hash[child.name] = element.singular? ? nil : []
    end
  end
  hash
end
content() click to toggle source

@private

# File lib/lolsoap/hash_builder.rb, line 48
def content
  node.text.to_s unless nil_value?
end
nil_value?() click to toggle source

@private

# File lib/lolsoap/hash_builder.rb, line 53
def nil_value?
  node.attribute_with_ns('nil', 'http://www.w3.org/2001/XMLSchema-instance')
end