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.
10 11 12 13 14 15 |
# File 'lib/reactor/cm/xml_response.rb', line 10 def initialize(xml) @xml_str = xml @xml = REXML::Document.new(xml) @handler = Reactor::ResponseHandler::XmlAttribute.new @xpath = Reactor::XPathExtractor.new(@xml) end |
Instance Attribute Details
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
8 9 10 |
# File 'lib/reactor/cm/xml_response.rb', line 8 def xml @xml end |
#xml_str ⇒ Object (readonly)
Returns the value of attribute xml_str.
8 9 10 |
# File 'lib/reactor/cm/xml_response.rb', line 8 def xml_str @xml_str end |
Instance Method Details
#ok? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/reactor/cm/xml_response.rb', line 21 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
17 18 19 |
# File 'lib/reactor/cm/xml_response.rb', line 17 def xpath(expr) @xpath.match(expr) end |