Class: Rainbow::Color::RGB

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

Instance Attribute Summary collapse

Attributes inherited from Indexed

#num

Attributes inherited from Rainbow::Color

#ground

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rainbow::Color

build, parse_hex_color

Constructor Details

#initialize(ground, *values) ⇒ RGB

Returns a new instance of RGB.

Raises:

  • (ArgumentError)


85
86
87
88
89
90
91
92
# File 'lib/rainbow/color.rb', line 85

def initialize(ground, *values)
  raise ArgumentError.new(
    "RGB value outside 0-255 range"
  ) if values.min < 0 or values.max > 255

  super(ground, 8)
  @r, @g, @b = values
end

Instance Attribute Details

#bObject (readonly)

Returns the value of attribute b.



79
80
81
# File 'lib/rainbow/color.rb', line 79

def b
  @b
end

#gObject (readonly)

Returns the value of attribute g.



79
80
81
# File 'lib/rainbow/color.rb', line 79

def g
  @g
end

#rObject (readonly)

Returns the value of attribute r.



79
80
81
# File 'lib/rainbow/color.rb', line 79

def r
  @r
end

Class Method Details

.to_ansi_domain(value) ⇒ Object



81
82
83
# File 'lib/rainbow/color.rb', line 81

def self.to_ansi_domain(value)
  (6 * (value / 256.0)).to_i
end

Instance Method Details

#codesObject



94
95
96
# File 'lib/rainbow/color.rb', line 94

def codes
  super + [5, code_from_rgb]
end