Class: Iz::HexColor

Inherits:
Object
  • Object
show all
Defined in:
lib/iz/hex_color.rb

Constant Summary collapse

REGEX =
/^([0-9a-f]{3}|[0-9a-f]{6})$/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hex_color) ⇒ HexColor

Returns a new instance of HexColor.



7
8
9
# File 'lib/iz/hex_color.rb', line 7

def initialize(hex_color)
  self.value = hex_color
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/iz/hex_color.rb', line 5

def value
  @value
end

Class Method Details

.is_hex_color?(value) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/iz/hex_color.rb', line 15

def self.is_hex_color?(value)
  val = value.to_s.dup
  return false unless val[0] == '#'

  val[0] = ''
  val =~ REGEX
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/iz/hex_color.rb', line 11

def valid?
  !!Iz::HexColor.is_hex_color?(value)
end