Class: Discordrb::ColourRGB

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/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

Instance Method Summary collapse

Constructor Details

#initialize(combined) ⇒ ColourRGB

Make a new colour from the combined value.

Examples:

Initialize a with a base 10 integer

ColourRGB.new(7506394) #=> ColourRGB
ColourRGB.new(0x7289da) #=> ColourRGB

Initialize a with a hexadecimal string

ColourRGB.new('7289da') #=> ColourRGB


27
28
29
30
31
32
# File 'lib/discordrb/colour_rgb.rb', line 27

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

#blueInteger (readonly)



14
15
16
# File 'lib/discordrb/colour_rgb.rb', line 14

def blue
  @blue
end

#combinedInteger (readonly) Also known as: to_i



17
18
19
# File 'lib/discordrb/colour_rgb.rb', line 17

def combined
  @combined
end

#greenInteger (readonly)



11
12
13
# File 'lib/discordrb/colour_rgb.rb', line 11

def green
  @green
end

#redInteger (readonly)



8
9
10
# File 'lib/discordrb/colour_rgb.rb', line 8

def red
  @red
end

Instance Method Details

#hexString Also known as: hexadecimal



35
36
37
# File 'lib/discordrb/colour_rgb.rb', line 35

def hex
  @combined.to_s(16)
end