Class: Rainbow::Color

### Home Classes Methods

### In Files

- lib/rainbow/color.rb

### Parent

Object

### Namespace

- CLASS Rainbow::Color::Indexed
- CLASS Rainbow::Color::Named
- CLASS Rainbow::Color::RGB

### Methods

- ::build
- ::parse_hex_color

### Class/Module Index

Quicksearch

- Rainbow
- Rainbow::Color
- Rainbow::Color::Indexed
- Rainbow::Color::Named
- Rainbow::Color::RGB
- Rainbow::Ext
- Rainbow::Ext::String
- Rainbow::Ext::String::InstanceMethods
- Rainbow::NullPresenter
- Rainbow::Presenter
- Rainbow::StringUtils
- Rainbow::Wrapper
- Sickill
- Sickill::Rainbow
- Object

No matching classes.

# Rainbow::Color

### Attributes

ground[R]

### Public Class Methods

build(ground, values) click to toggle source

    # File lib/rainbow/color.rb, line 6
    def self.build(ground, values)
      unless [1, 3].include?(values.size)
        fail ArgumentError,
          "Wrong number of arguments for color definition, should be 1 or 3"
      end

      color = values.size == 1 ? values.first : values

      case color
      when ::Fixnum
        Indexed.new(ground, color)
      when ::Symbol
        Named.new(ground, color)
      when ::Array
        RGB.new(ground, *color)
      when ::String
        RGB.new(ground, *parse_hex_color(color))
      end
    end

parse_hex_color(hex) click to toggle source

    # File lib/rainbow/color.rb, line 26
    def self.parse_hex_color(hex)
      hex = hex.gsub('#', '')
      r   = hex[0..1].to_i(16)
      g   = hex[2..3].to_i(16)
      b   = hex[4..5].to_i(16)

      [r, g, b]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.