Class: Iz::Hexadecimal

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

Constant Summary collapse

REGEX =
/^[0-9a-f]+$/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hexadecimal) ⇒ Hexadecimal

Returns a new instance of Hexadecimal.



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

def initialize(hexadecimal)
  self.value = hexadecimal
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.is_hexadecimal?(value) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/iz/hexadecimal.rb', line 15

def self.is_hexadecimal?(value)
  value.to_s =~ REGEX
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  !!Iz::Hexadecimal.is_hexadecimal?(value)
end