### Home Classes Methods

### In Files

- lib/term/ansicolor/rgb_triple.rb

### Parent

Object

### Methods

- ::[]
- ::from_array
- ::from_hash
- ::from_html
- ::new
- #==
- #blue
- #distance_to
- #gradient_to
- #gray?
- #green
- #html
- #initialize_copy
- #red
- #to_a
- #to_rgb_triple

### Included Modules

- Term::ANSIColor::RGBColorMetricsHelpers::WeightedEuclideanDistance

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Term
- Term::ANSIColor
- Term::ANSIColor::Attribute
- Term::ANSIColor::PPMReader
- Term::ANSIColor::RGBColorMetrics
- Term::ANSIColor::RGBColorMetrics::CIELab
- Term::ANSIColor::RGBColorMetrics::CIELab::CIELabTriple
- Term::ANSIColor::RGBColorMetrics::CIEXYZ
- Term::ANSIColor::RGBColorMetrics::CIEXYZ::CIEXYZTriple
- Term::ANSIColor::RGBColorMetrics::CompuPhase
- Term::ANSIColor::RGBColorMetrics::Euclidean
- Term::ANSIColor::RGBColorMetrics::NTSC
- Term::ANSIColor::RGBColorMetrics::YUV
- Term::ANSIColor::RGBColorMetrics::YUV::YUVTriple
- Term::ANSIColor::RGBColorMetricsHelpers
- Term::ANSIColor::RGBColorMetricsHelpers::NormalizeRGBTriple
- Term::ANSIColor::RGBColorMetricsHelpers::WeightedEuclideanDistance
- Term::ANSIColor::RGBTriple

No matching classes.

# Term::ANSIColor::RGBTriple

### Attributes

values[R]

### Public Class Methods

[](thing) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 39
    def self.[](thing)
      case
      when thing.respond_to?(:to_rgb_triple) then thing
      when thing.respond_to?(:to_ary)        then RGBTriple.from_array(thing.to_ary)
      when thing.respond_to?(:to_str)        then RGBTriple.from_html(thing.to_str.sub(/\Aon_/, '')) # XXX somewhat hacky
      when thing.respond_to?(:to_hash)       then RGBTriple.from_hash(thing.to_hash)
      else raise ArgumentError, "cannot convert #{thing.inspect} into #{self}"
      end
    end

from_array(array) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 35
    def self.from_array(array)
      new(*array)
    end

from_hash(options) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 27
    def self.from_hash(options)
      new(
        convert_value(options[:red]),
        convert_value(options[:green]),
        convert_value(options[:blue])
      )
    end

from_html(html) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 18
    def self.from_html(html)
      case html
      when /\A#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})\z/
        new(*$~.captures.map { |c| convert_value(c.to_i(16)) })
      when /\A#([0-9a-f])([0-9a-f])([0-9a-f])\z/
        new(*$~.captures.map { |c| convert_value(c.to_i(16) << 4) })
      end
    end

new(red, green, blue) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 49
    def initialize(red, green, blue)
      @values = [ red, green, blue ]
    end

### Public Instance Methods

==(other) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 86
    def ==(other)
      @values == other.values
    end

blue() click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 61
    def blue
      @values[2]
    end

distance_to(other, options = {}) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 90
    def distance_to(other, options = {})
      options[:metric] ||= RGBColorMetrics::CIELab
      options[:metric].distance(self, other)
    end

gradient_to(other, options = {}) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 101
    def gradient_to(other, options = {})
      options[:steps] ||= 16
      steps = options[:steps].to_i
      steps < 2 and raise ArgumentError, 'at least 2 steps are required'
      changes = other.values.zip(@values).map { |x, y| x - y }
      current = self
      gradient = [ current.dup ]
      s = steps - 1
      while s > 1
        current = current.dup
        gradient << current
        3.times do |i|
          current.values[i] += changes[i] / (steps - 1)
        end
        s -= 1
      end
      gradient << other
    end

gray?() click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 65
    def gray?
      red != 0 && red != 0xff && red == green && green == blue && blue == red
    end

green() click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 57
    def green
      @values[1]
    end

html() click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 69
    def html
      s = '#'
      @values.each { |c| s << '%02x' % c }
      s
    end

initialize_copy(other) click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 95
    def initialize_copy(other)
      r = super
      other.instance_variable_set :@values, @values.dup
      r
    end

red() click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 53
    def red
      @values[0]
    end

to_a() click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 82
    def to_a
      @values.dup
    end

to_rgb_triple() click to toggle source

    # File lib/term/ansicolor/rgb_triple.rb, line 75
    def to_rgb_triple
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.