module SpreadsheetBuilder::Palette

Public Class Methods

_color_from_input(input) click to toggle source
# File lib/spreadsheet_builder/palette.rb, line 19
def self._color_from_input(input)
  input = input.to_s
  if input =~ /^rgb/i
    _, r, g, b = input.match(/^rgba*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)[^\)]*/)
    r, g, b = [r, g, b].map(&:to_i)
    input = "##{Spreadsheet::Excel::Rgb.new(r, g, b).as_hex.ljust(6, "0")}"
  end

  # Assume a color is always found
  color = PALETTE.nearest_value(input).name.to_sym
  color
end