Class: TcpsnitchAnalyzer::ProportionStat

Inherits:
Object
  • Object
show all
Defined in:
lib/tcpsnitch_analyzer/proportion_stat.rb

Constant Summary collapse

@@count =
0
@@hash =
Hash.new(0)

Class Method Summary collapse

Class Method Details

.add_val(val) ⇒ Object



6
7
8
9
# File 'lib/tcpsnitch_analyzer/proportion_stat.rb', line 6

def self.add_val(val)
  @@count += 1
  @@hash[val] += 1
end


11
12
13
14
15
16
17
18
19
# File 'lib/tcpsnitch_analyzer/proportion_stat.rb', line 11

def self.print(options)
  puts "Proportion statistics:"

  @@hash.sort_by { |val, count| -count }.each do |val, count|
    pc = ((count.to_f/@@count) * 100).round(2)
    puts "#{pc}%".ljust(7) + "(#{count})".ljust(10) + "#{val}"
  end
  puts "100%".ljust(7) + "(#{@@count})" 
end