Class: Quack::Types::Integer

Inherits:
Quack::Type show all
Defined in:
lib/quack/types/integer.rb

Constant Summary collapse

PATTERN =
/\A\d+\z/

Instance Attribute Summary

Attributes inherited from Quack::Type

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Quack::Type

#already_coerced?, already_coerced?, #initialize, #to_s, #type_matches?

Constructor Details

This class inherits a constructor from Quack::Type

Class Method Details

.built_in_typesObject



9
10
11
# File 'lib/quack/types/integer.rb', line 9

def built_in_types
  [Fixnum, Bignum]
end

.matches?(value) ⇒ Boolean

Returns:



13
14
15
# File 'lib/quack/types/integer.rb', line 13

def matches?(value)
  already_coerced?(value) || !!(value.to_s.strip =~ PATTERN)
end

Instance Method Details

#to_coercedObject



18
19
20
# File 'lib/quack/types/integer.rb', line 18

def to_coerced
  already_coerced? ? value : value.to_i
end