Module: Sai::Decorator::RGBColors Abstract Private

Included in:
Sai::Decorator
Defined in:
lib/sai/decorator/rgb_colors.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

This module is abstract.

This module is meant to be included in the Sai::Decorator class to provide RGB color methods

RGB color methods for the Sai::Decorator class

Author:

Since:

  • 0.3.1

Instance Method Summary collapse

Instance Method Details

#on_rgb(red, green, blue) ⇒ Decorator

Apply an RGB color to the background

Examples:

decorator.on_rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[48;2;235;65;51mHello, world!\e[0m"

Parameters:

  • red (Integer) —

    the red component

  • green (Integer) —

    the green component

  • blue (Integer) —

    the blue component

Returns:

  • (Decorator) —

    a new instance of Decorator with the RGB color applied

Raises:

  • (ArgumentError) —

    if the RGB values are out of range

Author:

Since:

  • 0.1.0



30
31
32
33
34
35
36
# File 'lib/sai/decorator/rgb_colors.rb', line 30

def on_rgb(red, green, blue)
  [red, green, blue].each do |value|
    raise ArgumentError, "Invalid RGB value: #{red}, #{green}, #{blue}" unless value >= 0 && value <= 255
  end

  dup.tap { |duped| duped.instance_variable_set(:@background, [red, green, blue]) } #: Decorator
end

#rgb(red, green, blue) ⇒ Decorator

Apply an RGB color to the foreground

Examples:

decorator.rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[38;2;235;65;51mHello, world!\e[0m"

Parameters:

  • red (Integer) —

    the red component

  • green (Integer) —

    the green component

  • blue (Integer) —

    the blue component

Returns:

  • (Decorator) —

    a new instance of Decorator with the RGB color applied

Raises:

  • (ArgumentError) —

    if the RGB values are out of range

Author:

Since:

  • 0.1.0



55
56
57
58
59
60
61
# File 'lib/sai/decorator/rgb_colors.rb', line 55

def rgb(red, green, blue)
  [red, green, blue].each do |value|
    raise ArgumentError, "Invalid RGB value: #{red}, #{green}, #{blue}" unless value >= 0 && value <= 255
  end

  dup.tap { |duped| duped.instance_variable_set(:@foreground, [red, green, blue]) } #: Decorator
end