class Reactor::ResponseHandler::XmlAttribute

Attributes

context[RW]
response[RW]

Public Instance Methods

get(response, attribute) click to toggle source
# File lib/reactor/tools/response_handler/xml_attribute.rb, line 10
def get(response, attribute)
  @response = response
  @context = context

  name = attribute.name
  type = attribute.type

  method_name = "extract_#{type}"

  self.send(method_name, name)
end
multiple(elem, attributes) click to toggle source
# File lib/reactor/tools/response_handler/xml_attribute.rb, line 22
def multiple(elem, attributes)
  values = {}
  attributes.each do |attribute|
    values[attribute.name] = self.get(elem, attribute)
  end
  values
end

Protected Instance Methods

extract_schedule(name) click to toggle source
# File lib/reactor/tools/response_handler/xml_attribute.rb, line 77
def extract_schedule(name)
  schedule_entries = []
  self.response.xpath("//#{name}/listitem").each do |potential_schedule|
    entry = {}
    potential_schedule.children.find_all {|c| c.name == "dictitem" }.each do |item|
      key = item.children.find {|c| c.name == "key" }.text
      values_item = item.children.find {|c| c.name == "value" }
      values = values_item.children.find_all { |c| c.name == "listitem" }.map {|i| i.text.to_s }
      entry[key.to_sym] = values
    end
    schedule_entries << entry
  end

  schedule_entries
end
node() click to toggle source
# File lib/reactor/tools/response_handler/xml_attribute.rb, line 64
def node
  # TODO: clean up this bullshit
  if self.response.kind_of?(Reactor::Cm::XmlResponse)
    self.response.xml
  else
    self.response
  end
end
xpath(expr) click to toggle source
# File lib/reactor/tools/response_handler/xml_attribute.rb, line 73
def xpath(expr)
  Reactor::XPathExtractor.new(self.node).match(expr)
end

Private Instance Methods

extract_list(name) click to toggle source

Extracts a list value with the given name and returns an array of strings.

# File lib/reactor/tools/response_handler/xml_attribute.rb, line 43
def extract_list(name)
  result = self.xpath(".//#{name}/listitem/text()")
  result = result.kind_of?(Array) ? result : [result]

  result.map(&:to_s)
end
extract_signaturelist(name) click to toggle source

This shit will break with the slightest change of the CM.

# File lib/reactor/tools/response_handler/xml_attribute.rb, line 51
def extract_signaturelist(name)
  signatures = []
  self.xpath(".//#{name}/").each do |potential_signature|
    if (potential_signature.name.to_s == "listitem")
      attribute = potential_signature.children.first.text.to_s
      group = potential_signature.children.last.text.to_s
      signatures << {:attribute => attribute, :group => group}
    end
  end
  signatures
end
extract_string(name) click to toggle source

Extracts a string value with the given name and returns a string.

# File lib/reactor/tools/response_handler/xml_attribute.rb, line 33
def extract_string(name)
  result = self.xpath(".//#{name}/text()")
  if result.kind_of?(Array)
    return result.first
  else
    return result.to_s
  end
end