Class: HTTPLogAnalyzer::Stats::BarGraphItem
- Inherits:
-
Object
- Object
- HTTPLogAnalyzer::Stats::BarGraphItem
- Defined in:
- lib/http-log-analyzer/stats.rb
Instance Method Summary collapse
- #bar ⇒ Object
-
#initialize(label:, count:, total:, width: 50) ⇒ BarGraphItem
constructor
A new instance of BarGraphItem.
- #to_s ⇒ Object
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
#bar ⇒ Object
61 62 63 64 |
# File 'lib/http-log-analyzer/stats.rb', line 61 def n = (@fraction * @width).ceil.to_i ('.' * (@width - n)) + ('#' * n) end |
#to_s ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/http-log-analyzer/stats.rb', line 66 def to_s '%s %3d%% %6d %s' % [ , (@fraction * 100).ceil.to_i, @count, @label, ] end |