Class: Reuters::Response

Inherits:
Hash
  • Object
show all
Defined in:
lib/reuters/response.rb

Overview

Note:

All attributes for XML elements can be accessed via the attributes accessor.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body = {}) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
18
19
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



21
22
23
24
25
# 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

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



10
11
12
# File 'lib/reuters/response.rb', line 10

def attributes
  @attributes
end

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/reuters/response.rb', line 10

def body
  @body
end