module Hab::Formatter::Graph
Constants
- BAR_SIZE
Public Instance Methods
bar(value, max, color)
click to toggle source
# File lib/hab/formatter/graph.rb, line 9 def bar(value, max, color) percent = value.to_f / max.to_f blocks = (percent * BAR_SIZE).floor spaces = BAR_SIZE - blocks bar = ('■' * blocks).colorize(color) space = ' ' * spaces endpost = '|'.colorize(:light_black) "#{endpost}#{bar}#{space}#{endpost}" end
statbar(label, value, max)
click to toggle source
# File lib/hab/formatter/graph.rb, line 19 def statbar(label, value, max) description = label.to_s.ljust(7).colorize(stat_color(label)) chart = bar(value, max, stat_color(label)) of = "/#{max.to_i}".colorize(:light_black) numeric = "#{value.to_i}#{of}".rjust(10) "#{description} #{chart} #{numeric}" end