class Fog::ToHashDocument

Public Class Methods

new() click to toggle source
# File lib/fog/to_hash_document.rb, line 3
def initialize
  @stack = []
end

Public Instance Methods

body() click to toggle source
# File lib/fog/to_hash_document.rb, line 24
def body
  @stack.first
end
characters(string) click to toggle source
# File lib/fog/to_hash_document.rb, line 7
def characters(string)
  @value ||= ""
  @value << string.strip
end
end_element(name) click to toggle source
# File lib/fog/to_hash_document.rb, line 12
def end_element(name)
  last = @stack.pop
  if last.empty? && @value.empty?
    @stack.last[name.to_sym] = ""
  elsif last == { :i_nil => "true" }
    @stack.last[name.to_sym] = nil
  elsif !@value.empty?
    @stack.last[name.to_sym] = @value
  end
  @value = ""
end
response() click to toggle source
# File lib/fog/to_hash_document.rb, line 28
def response
  body
end
start_element(name, attributes = []) click to toggle source
# File lib/fog/to_hash_document.rb, line 32
def start_element(name, attributes = [])
  @value = ""
  parsed_attributes = {}
  until attributes.empty?
    if attributes.first.is_a?(Array)
      key, value = attributes.shift
    else
      key, value = attributes.shift, attributes.shift
    end
    parsed_attributes[key.gsub(":", "_").to_sym] = value
  end
  if @stack.last.is_a?(Array)
    @stack.last << { name.to_sym => parsed_attributes }
  else
    data = if @stack.empty?
             @stack.push(parsed_attributes)
             parsed_attributes
           elsif @stack.last[name.to_sym]
             unless @stack.last[name.to_sym].is_a?(Array)
               @stack.last[name.to_sym] = [@stack.last[name.to_sym]]
             end
             @stack.last[name.to_sym] << parsed_attributes
             @stack.last[name.to_sym].last
           else
             @stack.last[name.to_sym] = {}
             @stack.last[name.to_sym].merge!(parsed_attributes)
             @stack.last[name.to_sym]
           end
    @stack.push(data)
  end
end