Class: Rainbow::Color::RGB

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

Direct Known Subclasses

X11Named

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.



107
108
109
110
111
112
113
114
# File 'lib/rainbow/color.rb', line 107

def initialize(ground, *values)
  if values.min.negative? || values.max > 255
    raise ArgumentError, "RGB value outside 0-255 range"
  end

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

Instance Attribute Details

#bObject (readonly)

Returns the value of attribute b.



101
102
103
# File 'lib/rainbow/color.rb', line 101

def b
  @b
end

#gObject (readonly)

Returns the value of attribute g.



101
102
103
# File 'lib/rainbow/color.rb', line 101

def g
  @g
end

#rObject (readonly)

Returns the value of attribute r.



101
102
103
# File 'lib/rainbow/color.rb', line 101

def r
  @r
end

Class Method Details

.to_ansi_domain(value) ⇒ Object



103
104
105
# File 'lib/rainbow/color.rb', line 103

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

Instance Method Details

#codesObject



116
117
118
# File 'lib/rainbow/color.rb', line 116

def codes
  super + [5, code_from_rgb]
end