Class: ColorContrastCalc::ColorFunctionParser::ColorFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/color_contrast_calc/color_function_parser.rb

Overview

Hold information about a parsed RGB/HSL/HWB function.

This class is intended to be used internally in ColorFunctionParser, so do not rely on the current class name and its interfaces. They may change in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#schemeString (readonly)

Returns Type of function: ‘rgb’ or ‘hsl’.

Returns:

  • (String)

    Type of function: ‘rgb’ or ‘hsl’



175
176
177
# File 'lib/color_contrast_calc/color_function_parser.rb', line 175

def scheme
  @scheme
end

#sourceObject (readonly)

Returns the value of attribute source.



175
# File 'lib/color_contrast_calc/color_function_parser.rb', line 175

attr_reader :scheme, :source

Instance Method Details

#opacityFloat

Return the opacity of a color presented as a RGB/HSL/HWB function. The returned value is normalized to a floating number between 0 and 1.

Returns:

  • (Float)

    Normalized opacity



250
251
252
# File 'lib/color_contrast_calc/color_function_parser.rb', line 250

def opacity
  @opacity ||= @normalized.length == 3 ? 1.0 : @normalized.last
end

#opaque?true, false

Return true when the Color is completely opaque.

Returns:

  • (true, false)

    return true when the opacity equals 1.0



269
270
271
# File 'lib/color_contrast_calc/color_function_parser.rb', line 269

def opaque?
  opacity == Utils::MAX_OPACITY
end

#rgbArray<Integer>

Return the RGB value gained from a RGB/HSL/HWB function.

Returns:

  • (Array<Integer>)

    RGB value represented as an array

Raises:

  • (NotImplementedError)


227
228
229
# File 'lib/color_contrast_calc/color_function_parser.rb', line 227

def rgb
  raise NotImplementedError, 'Overwrite the method in a subclass'
end

#rgbaArray<Integer, Float>

Return the RGBA value gained from a RGB/HSL/HWB function. The opacity is normalized to a floating number between 0 and 1.

Returns:

  • (Array<Integer, Float>)

    RGBA value represented as an array.



260
261
262
# File 'lib/color_contrast_calc/color_function_parser.rb', line 260

def rgba
  rgb + [opacity]
end

#to_aArray<Integer, Float>

Return the parameters of a RGB/HSL/HWB function as an array of Integer/Float. The unit for H, S, L is assumed to be deg, %, % respectively.

Returns:

  • (Array<Integer, Float>)

    RGB/HSL/HWB value represented as an array



239
240
241
# File 'lib/color_contrast_calc/color_function_parser.rb', line 239

def to_a
  @normalized
end