class Chroma::RgbGenerator::FromHexStringValues

Public Class Methods

from_hex3(format, r, g, b) click to toggle source

Generates a {ColorModes::Rgb} from 3-character hexadecimal. @return [ColorModes::Rgb]

@param format [Symbol] color format @param r [String] red value @param g [String] green value @param b [String] blue value

# File lib/chroma/rgb_generator/from_hex_string_values.rb, line 30
def from_hex3(format, r, g, b)
  new(format || :hex3, r * 2, g * 2, b * 2)
end
from_hex6(format, r, g, b) click to toggle source

Generates a {ColorModes::Rgb} from 6-character hexadecimal. @return [ColorModes::Rgb]

@param format [Symbol] color format @param r [String] red value @param g [String] green value @param b [String] blue value

# File lib/chroma/rgb_generator/from_hex_string_values.rb, line 41
def from_hex6(format, r, g, b)
  new(format, r, g, b)
end
from_hex8(format, a, r, g, b) click to toggle source

Generates a {ColorModes::Rgb} from 8-character hexadecimal. @return [ColorModes::Rgb]

@param format [Symbol] color format @param r [String] red value @param g [String] green value @param b [String] blue value @param a [String] alpha value

# File lib/chroma/rgb_generator/from_hex_string_values.rb, line 53
def from_hex8(format, a, r, g, b)
  new(format || :hex8, r, g, b, a)
end
new(format, r, g, b, a = 'ff') click to toggle source

@param format [Symbol] color format @param r [String] red value @param g [String] green value @param b [String] blue value @param a [String] alpha value

# File lib/chroma/rgb_generator/from_hex_string_values.rb, line 9
def initialize(format, r, g, b, a = 'ff')
  @format = format || :hex
  @r, @g, @b, @a = r, g, b, a
end

Public Instance Methods

generate() click to toggle source

Generates a {ColorModes::Rgb}. @return [ColorModes::Rgb]

# File lib/chroma/rgb_generator/from_hex_string_values.rb, line 16
def generate
  r, g, b = [@r, @g, @b].map { |n| n.to_i(16) }
  a = @a.to_i(16) / 255.0
  [ColorModes::Rgb.new(r, g, b, a), @format]
end