Class: Rubycord::ColourRGB
- Inherits:
-
Object
- Object
- Rubycord::ColourRGB
- Defined in:
- lib/rubycord/colour_rgb.rb
Overview
A colour (red, green and blue values). Used for role colours. If you prefer the American spelling, the alias ColorRGB is also available.
Instance Attribute Summary collapse
-
#blue ⇒ Integer
readonly
The blue part of this colour (0-255).
-
#combined ⇒ Integer
(also: #to_i)
readonly
The colour's RGB values combined into one integer.
-
#green ⇒ Integer
readonly
The green part of this colour (0-255).
-
#red ⇒ Integer
readonly
The red part of this colour (0-255).
Instance Method Summary collapse
-
#hex ⇒ String
(also: #hexadecimal)
The colour as a hexadecimal.
-
#initialize(combined) ⇒ ColourRGB
constructor
Make a new colour from the combined value.
Constructor Details
#initialize(combined) ⇒ ColourRGB
Make a new colour from the combined value.
25 26 27 28 29 30 |
# File 'lib/rubycord/colour_rgb.rb', line 25 def initialize(combined) @combined = combined.is_a?(String) ? combined.to_i(16) : combined @red = (@combined >> 16) & 0xFF @green = (@combined >> 8) & 0xFF @blue = @combined & 0xFF end |
Instance Attribute Details
#blue ⇒ Integer (readonly)
Returns the blue part of this colour (0-255).
12 13 14 |
# File 'lib/rubycord/colour_rgb.rb', line 12 def blue @blue end |
#combined ⇒ Integer (readonly) Also known as: to_i
Returns the colour's RGB values combined into one integer.
15 16 17 |
# File 'lib/rubycord/colour_rgb.rb', line 15 def combined @combined end |
#green ⇒ Integer (readonly)
Returns the green part of this colour (0-255).
9 10 11 |
# File 'lib/rubycord/colour_rgb.rb', line 9 def green @green end |
#red ⇒ Integer (readonly)
Returns the red part of this colour (0-255).
6 7 8 |
# File 'lib/rubycord/colour_rgb.rb', line 6 def red @red end |
Instance Method Details
#hex ⇒ String Also known as: hexadecimal
Returns the colour as a hexadecimal.
33 34 35 |
# File 'lib/rubycord/colour_rgb.rb', line 33 def hex @combined.to_s(16) end |