Module: Colcolor

Defined in:
lib/colcolor.rb,
lib/colcolor/version.rb

Constant Summary collapse

COLORS =
TAGMAP( %i(black red green yellow blue magenta cyan white), 30..37)
BGCOLORS =
TAGMAP( %i( black red green yellow blue magenta cyan white), 40..47)
EXTRA =
TAGMAP( %i( clear bold underline blink reverse ), [0, 1, 4, 5, 7])
VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.TAGMAP(colors, codes) ⇒ Object



4
5
6
# File 'lib/colcolor.rb', line 4

def self.TAGMAP(colors, codes)
  Hash[ colors.zip(codes).map { |k, v| [k, "\e[#{v}m"] } ].freeze
end

Instance Method Details

#colco(*colors, regexp: /\S+/) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/colcolor.rb', line 12

def colco(*colors, regexp:/\S+/)
  cs = colors.dup
  self.gsub(regexp) do
    color = build_color_tag(cs.shift)
    color.empty? ? $& : (color + $& + EXTRA[:clear])
  end
end