Class: ColorConverters::HslStringConverter

Inherits:
BaseConverter show all
Defined in:
lib/color_converters/converters/hsl_string_converter.rb

Constant Summary

Constants inherited from BaseConverter

BaseConverter::IMPORT_DP, BaseConverter::OUTPUT_DP

Instance Attribute Summary

Attributes inherited from BaseConverter

#original_value, #rgba

Class Method Summary collapse

Methods inherited from BaseConverter

#alpha, #cielab, #cielch, #cmyk, factory, #hex, #hsb, #hsl, #hsv, inherited, #initialize, #name, #oklab, #oklch, #rgb, #xyz

Constructor Details

This class inherits a constructor from ColorConverters::BaseConverter

Class Method Details

.boundsObject



11
12
13
# File 'lib/color_converters/converters/hsl_string_converter.rb', line 11

def self.bounds
  HslConverter.bounds
end

.matches?(colour_input) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/color_converters/converters/hsl_string_converter.rb', line 5

def self.matches?(colour_input)
  return false unless colour_input.is_a?(String)

  colour_input.include?('hsl(') || colour_input.include?('hsla(')
end

.sanitize_input(colour_input) ⇒ Object



46
47
48
49
50
# File 'lib/color_converters/converters/hsl_string_converter.rb', line 46

def self.sanitize_input(colour_input)
  matches = colour_input.match(/hsla?\(([0-9.,%\s]+)\)/) || []
  h, s, l, a = matches[1]&.split(',')&.map(&:strip)
  { h: h, s: s, l: l, a: a }
end