Class: IbmPowerHmc::Parser
- Inherits:
-
Object
- Object
- IbmPowerHmc::Parser
- Defined in:
- lib/ibm_power_hmc/schema/parser.rb
Overview
Generic parser for HMC K2 XML responses.
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#entry ⇒ REXML::Element?
Return the first K2 entry element in the response.
-
#initialize(body) ⇒ Parser
constructor
A new instance of Parser.
-
#object(filter_type = nil) ⇒ IbmPowerHmc::AbstractRest?
Parse the first K2 entry element into an object.
Constructor Details
#initialize(body) ⇒ Parser
Returns a new instance of Parser.
10 11 12 |
# File 'lib/ibm_power_hmc/schema/parser.rb', line 10 def initialize(body) @doc = REXML::Document.new(body) end |
Class Method Details
.to_obj(entry, filter_type = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ibm_power_hmc/schema/parser.rb', line 31 def self.to_obj(entry, filter_type = nil) return if entry.nil? content = entry.elements["content[@type]"] return if content.nil? type = content.attributes["type"].split("=")[1] || filter_type.to_s return unless filter_type.nil? || filter_type.to_s == type Module.const_get("IbmPowerHmc::#{type}").new(entry) end |
Instance Method Details
#entry ⇒ REXML::Element?
Return the first K2 entry element in the response.
18 19 20 |
# File 'lib/ibm_power_hmc/schema/parser.rb', line 18 def entry @doc.elements["entry"] end |
#object(filter_type = nil) ⇒ IbmPowerHmc::AbstractRest?
Parse the first K2 entry element into an object.
27 28 29 |
# File 'lib/ibm_power_hmc/schema/parser.rb', line 27 def object(filter_type = nil) self.class.to_obj(entry, filter_type) end |