Module: Fasterer::Painter

Defined in:
lib/fasterer/painter.rb

Constant Summary collapse

COLOR_CODES =
{
  red: 31,
  green: 32,
}

Class Method Summary collapse

Class Method Details

.paint(string, color) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/fasterer/painter.rb', line 8

def self.paint(string, color)
  color_code = COLOR_CODES[color.to_sym]
  if color_code.nil?
    raise ArgumentError, "Color #{color} is not supported. Allowed colors are #{COLOR_CODES.keys.join(', ')}"
  end
  paint_with_code(string, color_code)
end

.paint_with_code(string, color_code) ⇒ Object



16
17
18
# File 'lib/fasterer/painter.rb', line 16

def self.paint_with_code(string, color_code)
  "\e[#{color_code}m#{string}\e[0m"
end