Module: Hex

Defined in:
lib/color/hex.rb

Overview

Offering functionality related to the hex color model.

Class Method Summary collapse

Class Method Details

.fill_hex_color(short_hex_color) ⇒ Object

Hex Colors can be represented with three characters, to work



6
7
8
9
10
# File 'lib/color/hex.rb', line 6

def self.fill_hex_color(short_hex_color)
  long_hex_color = "#".dup
  short_hex_color.each_char { |c| long_hex_color << (c * 2) unless c == "#" }
  long_hex_color.downcase
end

.hex?(color_to_test) ⇒ Boolean

Test wether a given color is a valid hex color.

Returns:

  • (Boolean)


13
14
15
16
17
18
19
# File 'lib/color/hex.rb', line 13

def self.hex?(color_to_test)
  if color_to_test.is_a? String
    color_to_test.match("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")
  else
    false
  end
end