Class: ColorConverters::RgbStringConverter

Inherits:
BaseConverter show all
Defined in:
lib/color_converters/converters/rgb_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/rgb_string_converter.rb', line 11

def self.bounds
  RgbConverter.bounds
end

.matches?(colour_input) ⇒ Boolean



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

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

  colour_input.include?('rgb(') || colour_input.include?('rgba(')
end

.sanitize_input(colour_input) ⇒ Object



49
50
51
52
53
# File 'lib/color_converters/converters/rgb_string_converter.rb', line 49

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