Class: RemoteAPI::XML::Response
- Inherits:
-
Object
- Object
- RemoteAPI::XML::Response
- Defined in:
- lib/remote_api/xml_response.rb
Instance Method Summary collapse
-
#[](xpath) ⇒ Object
equivalent to: xml.elements.text.
-
#each(xpath) ⇒ Object
equivalent to: xml.each_element(xpath) { |node| … }.
-
#initialize(data) ⇒ Response
constructor
A new instance of Response.
- #to_formatted_s ⇒ Object
Constructor Details
Instance Method Details
#[](xpath) ⇒ Object
equivalent to:
xml.elements[xpath].text
11 12 13 14 15 16 17 |
# File 'lib/remote_api/xml_response.rb', line 11 def [](xpath) if element = @data.elements[xpath] element.text else nil end end |
#each(xpath) ⇒ Object
equivalent to:
xml.each_element(xpath) { |node| ... }
21 22 23 24 25 26 |
# File 'lib/remote_api/xml_response.rb', line 21 def each(xpath) raise ArgumentError, 'You must supply a block to the "each" method' unless block_given? @data.each_element(xpath) do |node| yield self.class.new(node) end end |
#to_formatted_s ⇒ Object
28 29 30 31 |
# File 'lib/remote_api/xml_response.rb', line 28 def to_formatted_s output = '' @data.write(output, 0) end |