Class: Loupe::Color
- Inherits:
-
Object
- Object
- Loupe::Color
- Defined in:
- lib/loupe/color.rb
Overview
Color
This class is responsible for coloring strings.
Constant Summary collapse
- COLORS =
{ red: "31", green: "32", yellow: "33" }.freeze
Instance Method Summary collapse
-
#initialize(enabled) ⇒ Color
constructor
A new instance of Color.
- #p(string, color) ⇒ String
Constructor Details
#initialize(enabled) ⇒ Color
Returns a new instance of Color.
17 18 19 |
# File 'lib/loupe/color.rb', line 17 def initialize(enabled) @enabled = enabled end |
Instance Method Details
#p(string, color) ⇒ String
24 25 26 27 28 29 |
# File 'lib/loupe/color.rb', line 24 def p(string, color) return string unless @enabled color_code = COLORS[color] "\033[1;#{color_code}m#{string}\033[0m" end |