class HTTPLogAnalyzer::Stats
Constants
- Sections
Public Class Methods
new()
click to toggle source
# File lib/http-log-analyzer/stats.rb, line 23 def initialize @stats = Hash[ Sections.keys.map { |k| [k, {}] } ] end
Public Instance Methods
add(key, value)
click to toggle source
# File lib/http-log-analyzer/stats.rb, line 27 def add(key, value) if value table = @stats[key] or raise "No stats for key #{key.inspect}" table[value] ||= 0 table[value] += 1 end end
report()
click to toggle source
# File lib/http-log-analyzer/stats.rb, line 35 def report @stats.each do |field, counts| next if counts.empty? puts; puts "#{Sections[field]}:" total = counts.values.sum if field == :dates counts = counts.sort_by { |k, v| k } else counts = counts.sort_by { |k, v| v }.reverse[0..19] end counts.each do |label, count| puts ' %s' % BarGraphItem.new(label: label, count: count, total: total) end end end