Class: ColorContrastCalc::ColorFunctionParser::ColorFunction
- Inherits:
-
Object
- Object
- ColorContrastCalc::ColorFunctionParser::ColorFunction
- 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
-
#scheme ⇒ String
readonly
Type of function: ‘rgb’ or ‘hsl’.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#opacity ⇒ Float
Return the opacity of a color presented as a RGB/HSL/HWB function.
-
#opaque? ⇒ true, false
Return true when the Color is completely opaque.
-
#rgb ⇒ Array<Integer>
Return the RGB value gained from a RGB/HSL/HWB function.
-
#rgba ⇒ Array<Integer, Float>
Return the RGBA value gained from a RGB/HSL/HWB function.
-
#to_a ⇒ Array<Integer, Float>
Return the parameters of a RGB/HSL/HWB function as an array of Integer/Float.
Instance Attribute Details
#scheme ⇒ String (readonly)
Returns Type of function: ‘rgb’ or ‘hsl’.
175 176 177 |
# File 'lib/color_contrast_calc/color_function_parser.rb', line 175 def scheme @scheme end |
#source ⇒ Object (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
#opacity ⇒ Float
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.
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.
269 270 271 |
# File 'lib/color_contrast_calc/color_function_parser.rb', line 269 def opaque? opacity == Utils::MAX_OPACITY end |
#rgb ⇒ Array<Integer>
Return the RGB value gained from a RGB/HSL/HWB function.
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 |
#rgba ⇒ Array<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.
260 261 262 |
# File 'lib/color_contrast_calc/color_function_parser.rb', line 260 def rgba rgb + [opacity] end |
#to_a ⇒ Array<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.
239 240 241 |
# File 'lib/color_contrast_calc/color_function_parser.rb', line 239 def to_a @normalized end |