lib/rubyipmi/freeipmi/commands/fru.rb in rubyipmi-0.10.0 vs lib/rubyipmi/freeipmi/commands/fru.rb in rubyipmi-0.11.0
- old
+ new
@@ -1,26 +1,19 @@
module Rubyipmi::Freeipmi
-
class Fru < Rubyipmi::Freeipmi::BaseCommand
-
attr_accessor :list
DEFAULT_FRU = 'default_fru_device'
def initialize(opts = ObservableHash.new)
- super("ipmi-fru", opts)
- @list = {}
+ super("ipmi-fru", opts)
+ @list = {}
end
def get_from_list(key)
- if list.has_key?(DEFAULT_FRU)
- if list[DEFAULT_FRU].has_key?(key)
- list[DEFAULT_FRU][key]
- else
- nil
- end
- end
+ return unless list.key?(DEFAULT_FRU)
+ list[DEFAULT_FRU][key] if list[DEFAULT_FRU].key?(key)
end
def manufacturer
get_from_list('board_manufacturer')
end
@@ -38,28 +31,26 @@
end
# method to retrieve the raw fru data
def getfrus
command
- return @result
+ @result
end
def names
list.keys
end
# return the list of fru information in a hash
def list
- if @list.count < 1
- parse(getfrus)
- end
+ parse(getfrus) if @list.count < 1
@list
end
private
- def method_missing(method, *args, &block)
+ def method_missing(method, *_args, &_block)
name = method.to_s
fru = list.fetch(name, nil)
# if the user wanted some data from the default fru, lets show the data for the fru. Otherwise
# we return the Fru with the given name
if fru.nil?
@@ -74,22 +65,21 @@
end
end
# parse the fru information
def parse(data)
- if ! data.nil? and ! data.empty?
+ if !data.nil? && !data.empty?
parsed_data = []
data.lines.each do |line|
if line =~ /^FRU.*/
# this is the either the first line of of the fru or another fru
if parsed_data.count != 0
# we have reached a new fru device so lets record the previous fru
new_fru = FruData.new(parsed_data)
parsed_data = []
@list[new_fru[:name]] = new_fru
end
-
end
parsed_data << line
end
# process the last fru
if parsed_data.count != 0
@@ -97,56 +87,47 @@
new_fru = FruData.new(parsed_data)
parsed_data = []
@list[new_fru[:name]] = new_fru
end
end
- return @list
+ @list
end
# run the command and return result
def command
- value = runcmd
- if value
- return @result
- end
+ value = runcmd
+ return @result if value
end
-
end
class FruData < Hash
-
def name
self[:name]
end
def initialize(data)
parse(data)
end
# parse the fru information that should be an array of lines
def parse(data)
- if ! data.nil?
- 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_/, '')
- if ! value.nil?
- self[key] = value.strip
-
- end
+ 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
private
- def method_missing(method, *args, &block)
- self.fetch(method.to_s, nil)
+ def method_missing(method, *_args, &_block)
+ fetch(method.to_s, nil)
end
-
end
-end
\ No newline at end of file
+end