class CPUInfo::CPUS::CPU
Attributes
attributes[R]
Public Class Methods
new(cpuinfo)
click to toggle source
# File lib/cpuinfo.rb, line 23 def initialize(cpuinfo) @attributes = {} cpuinfo.lines.each do |line| matches = /^([^:]+):(.+)\n/.match(line) next unless matches attribute = matches[1].strip.gsub(/[^a-zA-Z_]/,'_') value = matches[2].strip if value =~ /^[0-9]+(\.0*)?$/ value = value.to_i elsif value =~ /^[0-9\.]$/ value = value.to_f elsif ['no', 'false'].include? value.downcase value = false elsif ['yes', 'true'].include? value.downcase value = true elsif attribute == 'flags' value = CPUFlags.new value end @attributes[attribute.to_sym] = value end end
Public Instance Methods
method_missing(sym, *parameters)
click to toggle source
# File lib/cpuinfo.rb, line 45 def method_missing(sym, *parameters) return @attributes[sym.to_sym] if parameters.empty? && @attributes.key?(sym.to_sym) @attributes[:flags].public_send(sym, *parameters) end