discorb-lib/discorb

View on GitHub
sig/discorb/color.rbs

Summary

Maintainability
Test Coverage
module Discorb
  #
  # Represents RGB color.
  class Color
    #
    # Create a color from a Integer.
    #
    # @param [Integer] value A color value.
    def initialize: (Integer value) -> void

    #
    # Integerize a color.
    #
    # @return [Integer] A color value.
    %a{pure}
    def to_i: -> Integer

    #
    # Convert a color to a hexadecimal value.
    #
    # @return [String] A hexadecimal value.
    %a{pure}
    def to_hex: -> String

    #
    # Convert a color to RGB array.
    #
    # @return [Array(Integer, Integer, Integer)] A RGB array.
    %a{pure}
    def to_rgb: -> [Integer, Integer, Integer]

    alias to_a to_rgb
    alias deconstruct to_rgb

    #
    # Convert a color to RGB hash.
    #
    # @return [Hash{:r, :g, :b => Integer}] A RGB hash.
    %a{pure}
    def to_rgb_hash: -> { r: Integer, g: Integer, b: Integer }

    alias deconstruct_keys to_rgb_hash

    #
    # Converts a color to a `#000000` string.
    #
    # @return [String] Converted string.
    %a{pure}
    def to_s: -> String

    %a{pure}
    def inspect: -> String

    #
    # Create a color from a hexadecimal string.
    #
    # @param [String] hex A hexadecimal string.
    #
    # @return [Discorb::Color] A color object.
    def self.from_hex: (String hex) -> Discorb::Color

    #
    # Create a color from a RGB array.
    #
    # @param [Integer] red A red value.
    # @param [Integer] green A green value.
    # @param [Integer] blue A blue value.
    #
    # @return [Discorb::Color] A color object.
    def self.from_rgb: (
      Integer red,
      Integer green,
      Integer blue
    ) -> Discorb::Color

    #
    # Create a color from a Discord's color.
    # Currently these colors are supported:
    #
    # | Color Name | Hexadecimal |
    # |------------|------------|
    # | `:teal` | `#1abc9c` |
    # | `:dark_teal` | `#11806a` |
    # | `:green` | `#2ecc71` |
    # | `:dark_green` | `#1f8b4c` |
    # | `:blue` | `#3498db` |
    # | `:dark_blue` | `#206694` |
    # | `:purple` | `#9b59b6` |
    # | `:dark_purple` | `#71368a` |
    # | `:magenta` | `#e91e63` |
    # | `:dark_magenta` | `#ad1457` |
    # | `:gold` | `#f1c40f` |
    # | `:dark_gold` | `#c27c0e` |
    # | `:orange` | `#e67e22` |
    # | `:dark_orange` | `#a84300` |
    # | `:red` | `#e74c3c` |
    # | `:dark_red` | `#992d22` |
    # | `:lighter_grey` | `#95a5a6` |
    # | `:lighter_gray` | `#95a5a6` |
    # | `:dark_grey` | `#607d8b` |
    # | `:dark_gray` | `#607d8b` |
    # | `:light_grey` | `#979c9f` |
    # | `:light_gray` | `#979c9f` |
    # | `:darker_grey` | `#546e7a` |
    # | `:darker_gray` | `#546e7a` |
    # | `:og_blurple` | `#7289da` |
    # | `:blurple` | `#5865f2` |
    # | `:greyple` | `#99aab5` |
    # | `:dark_theme` | `#36393f` |
    # | `:fuchsia` | `#eb459e` |
    # | `:dark_teal` | `#11806a` |
    # | `:green` | `#2ecc71` |
    # | `:dark_green` | `#1f8b4c` |
    # | `:blue` | `#3498db` |
    # | `:dark_blue` | `#206694` |
    # | `:purple` | `#9b59b6` |
    # | `:dark_purple` | `#71368a` |
    # | `:magenta` | `#e91e63` |
    # | `:dark_magenta` | `#ad1457` |
    # | `:gold` | `#f1c40f` |
    # | `:dark_gold` | `#c27c0e` |
    # | `:orange` | `#e67e22` |
    # | `:dark_orange` | `#a84300` |
    # | `:red` | `#e74c3c` |
    # | `:dark_red` | `#992d22` |
    # | `:lighter_grey` | `#95a5a6` |
    # | `:lighter_gray` | `#95a5a6` |
    # | `:dark_grey` | `#607d8b` |
    # | `:dark_gray` | `#607d8b` |
    # | `:light_grey` | `#979c9f` |
    # | `:light_gray` | `#979c9f` |
    # | `:darker_grey` | `#546e7a` |
    # | `:darker_gray` | `#546e7a` |
    # | `:og_blurple` | `#7289da` |
    # | `:blurple` | `#5865f2` |
    # | `:greyple` | `#99aab5` |
    # | `:dark_theme` | `#36393f` |
    # | `:fuchsia` | `#eb459e` |
    #
    # @param [Symbol] color A Discord color name.
    #
    # @return [Discorb::Color] A color object.
    def self.[]: (Symbol color) -> Discorb::Color

    # Returns the value of attribute value.
    attr_accessor value: untyped
  end
end