Module: ColorContrastCalc::Sorter::KeyTypes

Defined in:
lib/color_contrast_calc/sorter.rb

Overview

Constants used as a second argeument of Sorter.compile_compare_function()

The constants COLOR, COMPONENTS and HEX are expected to be used as a second argument of Sorter.compile_compare_function()

Constant Summary collapse

COLOR =

The function returned by Sorter.compile_compare_function() expects instances of Color as key values when this constants is specified.

:color
COMPONENTS =

The function returned by Sorter.compile_compare_function() expects RGB or HSL values as key values when this constants is specified.

:components
HEX =

The function returned by Sorter.compile_compare_function() expects hex color codes as key values when this constants is specified.

:hex

Class Method Summary collapse

Class Method Details

.guess(color, key_mapper = nil) ⇒ :color, ...

Returns COLOR, COMPONENTS or HEX when a possible key value is passed.

Parameters:

  • color (Color, Array<Numeric>, String)

    Possible key value

  • key_mapper (Proc) (defaults to: nil)

    Function which retrieves a key value from color, that means key_mapper[color] returns a key value

Returns:

  • (:color, :components, :hex)

    Symbol that represents a key type



63
64
65
66
# File 'lib/color_contrast_calc/sorter.rb', line 63

def self.guess(color, key_mapper = nil)
  key = key_mapper ? key_mapper[color] : color
  CLASS_TO_TYPE[key.class]
end