Class: Iz::HexColor
- Inherits:
-
Object
- Object
- Iz::HexColor
- Defined in:
- lib/iz/hex_color.rb
Constant Summary collapse
- REGEX =
/^([0-9a-f]{3}|[0-9a-f]{6})$/i
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hex_color) ⇒ HexColor
constructor
A new instance of HexColor.
- #valid? ⇒ Boolean
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
#value ⇒ Object
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
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
11 12 13 |
# File 'lib/iz/hex_color.rb', line 11 def valid? !!Iz::HexColor.is_hex_color?(value) end |