Class: Reuters::Response
- Inherits:
-
Hash
- Object
- Hash
- Reuters::Response
- 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
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#body ⇒ Object
Returns the value of attribute body.
Instance Method Summary collapse
-
#initialize(body = {}) ⇒ Response
constructor
A new instance of Response.
- #method_missing(name) ⇒ Object
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 26 27 28 29 30 31 32 33 34 |
# File 'lib/reuters/response.rb', line 21 def method_missing(name) if key?(name) val = self[name] case val when String then val when Array val.collect do |v| self.class.new v end else self.class.new val end end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/reuters/response.rb', line 10 def attributes @attributes end |
#body ⇒ Object
Returns the value of attribute body.
10 11 12 |
# File 'lib/reuters/response.rb', line 10 def body @body end |