class RGBUtils::HexToRGBConverter

Attributes

color[RW]

Public Class Methods

new(color) click to toggle source
# File lib/rgb_utils/converters/hex_to_rgb_converter.rb, line 3
def initialize(color)
  @color = color
end

Public Instance Methods

convert() click to toggle source
# File lib/rgb_utils/converters/hex_to_rgb_converter.rb, line 7
def convert
  return color if color.is_a?(RGB)

  @rgb ||= begin
    red, green, blue = capture_colors

    RGB.new(red: red, green: green, blue: blue)
  end
end

Private Instance Methods

capture_colors() click to toggle source
# File lib/rgb_utils/converters/hex_to_rgb_converter.rb, line 21
def capture_colors
  @capture_colors ||= begin
    WebSafeToHexConverter
      .convert(color)
      .match(/(\w{2})(\w{2})(\w{2})/)
      .captures
      .map { |color_node| color_node.to_i(16) }
  end
end