Parent

Prawn::Svg::Color

Public Class Methods

color_to_hex(color_string) click to toggle source
# File lib/prawn/svg/color.rb, line 13
def self.color_to_hex(color_string)
  color_string.scan(/([^(\s]+(\([^)]*\))?)/).detect do |color, *_|
    if m = color.match(/\A#([0-9a-f])([0-9a-f])([0-9a-f])\z/)
      break "#{m[1] * 2}#{m[2] * 2}#{m[3] * 2}"
    elsif color.match(/\A#[0-9a-f]{6}\z/)
      break color[1..6]
    elsif hex = HTML_COLORS[color.downcase]
      break hex
    elsif m = color.match(RGB_REGEXP)
      break (1..3).collect do |n|
        value = m[n].to_f
        value *= 2.55 if m[n][-1..-1] == '%'
        "%02x" % clamp(value.round, 0, 255)
      end.join
    end
  end
end

Protected Class Methods

clamp(value, min_value, max_value) click to toggle source
# File lib/prawn/svg/color.rb, line 32
def self.clamp(value, min_value, max_value)
  [[value, min_value].max, max_value].min
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.