Class: Sickill::Rainbow::AnsiColor

Inherits:
Object
  • Object
show all
Defined in:
lib/ansi_color.rb

Overview

Retrieve ANSI color code from a color name, an html color or an RGB color

Instance Method Summary collapse

Constructor Details

#initialize(ground, *color) ⇒ AnsiColor

ground is one of :foreground, :background color is one of this 3 formats: name, html, rgb



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

def initialize(ground, *color)
  @ground = ground

  if color.size == 1
    @color = color.first
  else
    @color = color
  end
end

Instance Method Details

#codeObject

Get the ANSI color code.



23
24
25
26
27
28
29
# File 'lib/ansi_color.rb', line 23

def code
  case @color
    when Symbol then code_from_name
    when String then code_from_html
    when Array then code_from_rgb
  end
end