Class: Rainbow::Color::Named

Inherits:
Indexed show all
Defined in:
lib/rainbow/color.rb

Constant Summary collapse

NAMES =
{
  black:   0,
  red:     1,
  green:   2,
  yellow:  3,
  blue:    4,
  magenta: 5,
  cyan:    6,
  white:   7,
  default: 9,
}

Instance Attribute Summary

Attributes inherited from Indexed

#num

Attributes inherited from Rainbow::Color

#ground

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Indexed

#codes

Methods inherited from Rainbow::Color

build, parse_hex_color

Constructor Details

#initialize(ground, name) ⇒ Named

Returns a new instance of Named.



78
79
80
81
82
83
84
85
# File 'lib/rainbow/color.rb', line 78

def initialize(ground, name)
  unless Named.color_names.include?(name)
    fail ArgumentError,
      "Unknown color name, valid names: #{Named.color_names.join(', ')}"
  end

  super(ground, NAMES[name])
end

Class Method Details

.color_namesObject



74
75
76
# File 'lib/rainbow/color.rb', line 74

def self.color_names
  NAMES.keys
end