Class: Reactor::Cm::XmlResponse
- Inherits:
-
Object
- Object
- Reactor::Cm::XmlResponse
- Defined in:
- lib/reactor/cm/xml_response.rb
Instance Attribute Summary collapse
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
-
#xml_str ⇒ Object
readonly
Returns the value of attribute xml_str.
Instance Method Summary collapse
-
#initialize(xml) ⇒ XmlResponse
constructor
A new instance of XmlResponse.
- #ok? ⇒ Boolean
- #xpath(expr) ⇒ Object
Constructor Details
#initialize(xml) ⇒ XmlResponse
Returns a new instance of XmlResponse.
14 15 16 17 18 |
# File 'lib/reactor/cm/xml_response.rb', line 14 def initialize(xml) @xml_str = xml @xml = REXML::Document.new(xml) @handler = Reactor::ResponseHandler::XmlAttribute.new end |
Instance Attribute Details
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
11 12 13 |
# File 'lib/reactor/cm/xml_response.rb', line 11 def xml @xml end |
#xml_str ⇒ Object (readonly)
Returns the value of attribute xml_str.
12 13 14 |
# File 'lib/reactor/cm/xml_response.rb', line 12 def xml_str @xml_str end |
Instance Method Details
#ok? ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/reactor/cm/xml_response.rb', line 27 def ok? xp = xpath('//cm-code') if xp.is_a?(Array) codes = xp.map { |result| result.attribute('numeric').value }.uniq return codes.size == 1 && codes.first == '200' end xp.attribute('numeric').value == '200' end |
#xpath(expr) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/reactor/cm/xml_response.rb', line 20 def xpath(expr) arr = REXML::XPath.match(@xml, expr) return arr.first if arr.length == 1 return arr end |