Class: PVN::ColorFormatter

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/pvn/util/color_formatter.rb

Direct Known Subclasses

Log::Formatter, Status::Formatter

Instance Method Summary collapse

Instance Method Details

#add_field(value, field) ⇒ Object



25
26
27
# File 'lib/pvn/util/color_formatter.rb', line 25

def add_field value, field
  colorize(value, field) + pad(value, field)
end

#colorize(what, field) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/pvn/util/color_formatter.rb', line 16

def colorize what, field
  colors = colors field
  return what if colors.nil? || colors.empty?
  colors.each do |col|
    what = what.send col
  end
  what
end

#pad(what, field) ⇒ Object



11
12
13
14
# File 'lib/pvn/util/color_formatter.rb', line 11

def pad what, field
  nspaces = [ width(field) - what.length, 1 ].max
  " " * nspaces
end