class Reuters::Response

This class parses Savon response bodies into more practical accessible objects, by using a recursive strategy for parsing the content.

@note All attributes for XML elements can be accessed via the

attributes accessor.

Attributes

attributes[RW]
body[RW]

Public Class Methods

new(body = {}) click to toggle source
# File lib/reuters/response.rb, line 12
def initialize(body = {})
  unless body.empty?
    merge! body
    attribs = body.keep_if { |k| k.match(/@/) }
    attribs = Hash[attribs.map { |k, v| [k.to_s.gsub(/@/, '').to_sym, v] }]
    @attributes = self.class.new attribs
  end
end

Public Instance Methods

method_missing(name) click to toggle source
# File lib/reuters/response.rb, line 21
def method_missing(name)
  if key?((key = name)) || key?((key = name.to_s))
    determine_value self[key]
  end
end

Private Instance Methods

determine_value(val) click to toggle source
# File lib/reuters/response.rb, line 29
def determine_value(val)
  case val
  when Array
    val.dup.collect { |v| determine_value v }
  when Hash
    self.class.new val.dup
  else
    val
  end
end