Class: Sickill::Rainbow::AnsiRgb

### Home Classes Methods

### In Files

- lib/ansi_rgb.rb

### Parent

Object

### Methods

- ::new
- #code

### Class/Module Index

Quicksearch

- Sickill
- Sickill::Rainbow
- Sickill::Rainbow::AnsiColor
- Sickill::Rainbow::AnsiRgb
- Sickill::Rainbow::RGB

No matching classes.

# Sickill::Rainbow::AnsiRgb

Retrieve ANSI color code from RGB color.

### Public Class Methods

new(ground, rgb) click to toggle source

`ground` is one of :foreground, :background `rgb` is an array of 3 values between 0 and 255.

    # File lib/ansi_rgb.rb, line 9
    def initialize(ground, rgb)
      if RGB.outside_range?(rgb)
        raise ArgumentError.new("RGB value outside 0-255 range")
      end

      @ground_code = { :foreground => 38, :background => 48 }[ground]
      @red, @green, @blue = rgb[0], rgb[1], rgb[2]
    end

### Public Instance Methods

code() click to toggle source

Get the ANSI color code for this RGB color.

    # File lib/ansi_rgb.rb, line 19
    def code
      index = 16 +
              RGB.to_ansi_domain(@red) * 36 +
              RGB.to_ansi_domain(@green) * 6 +
              RGB.to_ansi_domain(@blue)

      "#{@ground_code};5;#{index}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.