Class: IbmPowerHmc::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm_power_hmc/schema/parser.rb

Overview

Generic parser for HMC K2 XML responses.

Direct Known Subclasses

FeedParser

Class Method Summary collapse

Instance Method Summary collapse

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

#entryREXML::Element?

Return the first K2 entry element in the response.

Returns:

  • (REXML::Element, nil)

    The first entry element.



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.

Parameters:

  • filter_type (String) (defaults to: nil)

    Entry type must match the specified type.

Returns:



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