class RawkLog::StatHash
Public Class Methods
new()
click to toggle source
# File lib/rawk_log/stat_hash.rb, line 6 def initialize @stats = Hash.new end
Public Instance Methods
add(key, time)
click to toggle source
# File lib/rawk_log/stat_hash.rb, line 14 def add(key, time) stat = @stats[key] || (@stats[key] = RawkLog::Stat.new(key)) stat.add(time) end
empty?()
click to toggle source
# File lib/rawk_log/stat_hash.rb, line 10 def empty? @stats.empty? end
print(args={:sort_by => 'key', :ascending => true, :limit => nil})
click to toggle source
# File lib/rawk_log/stat_hash.rb, line 19 def print(args={:sort_by => 'key', :ascending => true, :limit => nil}) values = @stats.values return Stat::DEFAULT_LABEL_SIZE if values.empty? order = (args[:ascending] || args[:ascending].nil?) ? 1 : -1 values.sort! { |a, b| as = a.send(args[:sort_by]) bs = b.send(args[:sort_by]) (as && bs) ? order*(as<=>bs) : 0 } #values.sort! {|a,b| a.key<=>b.key} limit = args[:limit] if limit values = values[0, limit] end @label_size = values.collect { |v| v.key.size }.max @label_size = Stat::DEFAULT_LABEL_SIZE if @label_size < Stat::DEFAULT_LABEL_SIZE puts values[0].header(@label_size) for stat in values puts stat.to_s(@label_size) end @label_size end