Class: HTTPLogAnalyzer::Stats::BarGraphItem

Inherits:
Object
  • Object
show all
Defined in:
lib/http-log-analyzer/stats.rb

Instance Method Summary collapse

Constructor Details

#initialize(label:, count:, total:, width: 50) ⇒ BarGraphItem

Returns a new instance of BarGraphItem.



53
54
55
56
57
58
59
# File 'lib/http-log-analyzer/stats.rb', line 53

def initialize(label:, count:, total:, width: 50)
  @label = label
  @count = count
  @total = total
  @width = width
  @fraction = @count.to_f / @total
end

Instance Method Details

#barObject



61
62
63
64
# File 'lib/http-log-analyzer/stats.rb', line 61

def bar
  n = (@fraction * @width).ceil.to_i
  ('.' * (@width - n)) + ('#' * n)
end

#to_sObject



66
67
68
69
70
71
72
73
# File 'lib/http-log-analyzer/stats.rb', line 66

def to_s
  '%s %3d%% %6d  %s' % [
    bar,
    (@fraction * 100).ceil.to_i,
    @count,
    @label,
  ]
end