class Discordrb::ColorRGB

A colour (red, green and blue values). Used for role colours. If you prefer the American spelling, the alias {ColorRGB} is also available.

Attributes

blue[R]

@return [Integer] the blue part of this colour (0-255).

combined[R]

@return [Integer] the colour's RGB values combined into one integer.

green[R]

@return [Integer] the green part of this colour (0-255).

red[R]

@return [Integer] the red part of this colour (0-255).

to_i[R]

@return [Integer] the colour's RGB values combined into one integer.

Public Class Methods

new(combined) click to toggle source

Make a new colour from the combined value. @param combined [Integer, String] The colour's RGB values combined into one integer or a hexadecimal string @example Initialize a with a base 10 integer

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

@example Initialize a with a hexadecimal string

ColourRGB.new('7289da') #=> ColourRGB
# File lib/discordrb/data.rb, line 4214
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

Public Instance Methods

hex() click to toggle source

@return [String] the colour as a hexadecimal.

# File lib/discordrb/data.rb, line 4222
def hex
  @combined.to_s(16)
end
Also aliased as: hexadecimal
hexadecimal()
Alias for: hex