class PiSys::Stats
Public Class Methods
new(key, variations)
click to toggle source
# File lib/pi-sys/stats.rb, line 3 def initialize(key, variations) @key, @variations = key, variations STATS[@key] = {} if @variations @variations.each { |method| self.class.send(:define_method, method, Proc.new{ STATS[@key][method.to_sym ] }) } end end
Public Instance Methods
to_hash(statistic, output, start_index=0) { |data| ... }
click to toggle source
# File lib/pi-sys/stats.rb, line 14 def to_hash(statistic, output, start_index=0) output.strip.split("\n")[start_index..-1].each do |data_line| data = data_line.split(' ') unless data.empty? if statistic.kind_of? Array STATS[statistic[0]] ||= {} STATS[statistic[0]][statistic[1]] ||= {} STATS[statistic[0]][statistic[1]].merge!(yield(data)) if block_given? else STATS[statistic] ||= {} STATS[statistic].merge!(yield(data)) if block_given? end end end STATS[statistic] end
Private Instance Methods
fetch()
click to toggle source
# File lib/pi-sys/stats.rb, line 37 def fetch reset end
reset()
click to toggle source
# File lib/pi-sys/stats.rb, line 33 def reset STATS[@key] = {} end
run_command(command)
click to toggle source
# File lib/pi-sys/stats.rb, line 41 def run_command(command) begin `#{command}` rescue Errno::ENOENT => e nil end end