Class: MEACControl::XML::Response
- Inherits:
-
Object
- Object
- MEACControl::XML::Response
- Defined in:
- lib/meac_control/xml/response.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
- #error_messages ⇒ Object
- #errors ⇒ Object
- #errors? ⇒ Boolean
-
#initialize(xml, request = nil) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #to_xml ⇒ Object
Constructor Details
#initialize(xml, request = nil) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/meac_control/xml/response.rb', line 9 def initialize(xml, request = nil) @xml = ::Nokogiri::XML(xml) @request = request raise(MEACControl::XML::InvalidResponse, @xml.to_s) if @xml.root.nil? end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/meac_control/xml/response.rb', line 7 def request @request end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
7 8 9 |
# File 'lib/meac_control/xml/response.rb', line 7 def xml @xml end |
Instance Method Details
#error_messages ⇒ Object
37 38 39 40 41 |
# File 'lib/meac_control/xml/response.rb', line 37 def errors.map do |error| error['Message'] end end |
#errors ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/meac_control/xml/response.rb', line 27 def errors @xml.xpath('/Packet/DatabaseManager/ERROR').map do |error| data = {} error.each do |key, value| data[key] = value end data end end |
#errors? ⇒ Boolean
23 24 25 |
# File 'lib/meac_control/xml/response.rb', line 23 def errors? !@xml.xpath('/Packet/DatabaseManager/ERROR').empty? end |
#ok? ⇒ Boolean
19 20 21 |
# File 'lib/meac_control/xml/response.rb', line 19 def ok? !errors? end |
#to_xml ⇒ Object
15 16 17 |
# File 'lib/meac_control/xml/response.rb', line 15 def to_xml @xml.to_s end |