Class: Discordrb::ColourRGB

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

Parameters:

  • combined (Integer, String)

    The colour's RGB values combined into one integer or a hexadecimal string


3483
3484
3485
3486
3487
3488
# File 'lib/discordrb/data.rb', line 3483

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)

Returns the blue part of this colour (0-255).

Returns:

  • (Integer)

    the blue part of this colour (0-255).


3471
3472
3473
# File 'lib/discordrb/data.rb', line 3471

def blue
  @blue
end

#combinedInteger (readonly)

Returns the colour's RGB values combined into one integer.

Returns:

  • (Integer)

    the colour's RGB values combined into one integer.


3474
3475
3476
# File 'lib/discordrb/data.rb', line 3474

def combined
  @combined
end

#greenInteger (readonly)

Returns the green part of this colour (0-255).

Returns:

  • (Integer)

    the green part of this colour (0-255).


3468
3469
3470
# File 'lib/discordrb/data.rb', line 3468

def green
  @green
end

#redInteger (readonly)

Returns the red part of this colour (0-255).

Returns:

  • (Integer)

    the red part of this colour (0-255).


3465
3466
3467
# File 'lib/discordrb/data.rb', line 3465

def red
  @red
end

Instance Method Details

#hexString Also known as: hexadecimal

Returns the colour as a hexadecimal.

Returns:

  • (String)

    the colour as a hexadecimal.


3491
3492
3493
# File 'lib/discordrb/data.rb', line 3491

def hex
  @combined.to_s(16)
end