class Derrick::CLI::AggregateFormatter
Public Class Methods
new(aggregate)
click to toggle source
# File lib/derrick/cli.rb, line 52 def initialize(aggregate) @aggregate = Hash[aggregate.sort_by { |p, a| -a.count }] end
Public Instance Methods
each() { |render_header| ... }
click to toggle source
# File lib/derrick/cli.rb, line 56 def each yield render_header @aggregate.each { |n, s| yield render_line(n, s) } end
key_size()
click to toggle source
# File lib/derrick/cli.rb, line 89 def key_size @key_size ||= @aggregate.keys.map(&:size).max end
render_header()
click to toggle source
# File lib/derrick/cli.rb, line 61 def render_header [ 'Pattern'.ljust(key_size), 'Count'.rjust(6), 'Exp'.rjust(4), 'Type', ].join(' ') end
render_line(name, stats)
click to toggle source
# File lib/derrick/cli.rb, line 70 def render_line(name, stats) [ name.ljust(key_size), stats.count.to_s.rjust(6), "#{(stats.expirable_ratio * 100).round}%".rjust(4), types_summary(stats) ].join(' ') end
types_summary(stats)
click to toggle source
# File lib/derrick/cli.rb, line 79 def types_summary(stats) if stats.types_count.size == 1 stats.types_count.keys.first else stats.types_ratio.map do |type, ratio| "#{type}: #{(ratio * 100).round}%" end.join(',') end end