Class: Rubyipmi::Freeipmi::FruData

Inherits:
Hash
  • Object
show all
Defined in:
lib/rubyipmi/freeipmi/commands/fru.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ FruData

Returns a new instance of FruData.



107
108
109
# File 'lib/rubyipmi/freeipmi/commands/fru.rb', line 107

def initialize(data)
  parse(data)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_args, &_block) ⇒ Object (private)



129
130
131
# File 'lib/rubyipmi/freeipmi/commands/fru.rb', line 129

def method_missing(method, *_args, &_block)
  fetch(method.to_s, nil)
end

Instance Method Details

#nameObject



103
104
105
# File 'lib/rubyipmi/freeipmi/commands/fru.rb', line 103

def name
  self[:name]
end

#parse(data) ⇒ Object

parse the fru information that should be an array of lines



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rubyipmi/freeipmi/commands/fru.rb', line 112

def parse(data)
  return unless data
  data.each do |line|
    key, value = line.split(':', 2)
    if key =~ /^FRU.*/
      if value =~ /([\w\s]*)\(.*\)/
        self[:name] = $~[1].strip.gsub(/\ /, '_').downcase
      end
    else
      key = key.strip.gsub(/\ /, '_').downcase.gsub(/fru_/, '')
      self[key] = value.strip unless value.nil?
    end
  end
end