Class: Rbdantic::Validators::Types::Integer
- Defined in:
- lib/rbdantic/validators/types/integer.rb
Constant Summary
Constants inherited from Number
Number::FLOAT_TOLERANCE_FACTOR, Number::MIN_FLOAT_TOLERANCE
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Number
Methods inherited from Base
#initialize, #validate, #validate_constraints
Constructor Details
This class inherits a constructor from Rbdantic::Validators::Types::Base
Instance Method Details
#coerce(value) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/rbdantic/validators/types/integer.rb', line 17 def coerce(value) case value when ::Integer then value when ::Float then value.to_i if value == value.floor when ::String then Integer(value) rescue nil else nil end end |
#expected_type_name ⇒ Object
13 14 15 |
# File 'lib/rbdantic/validators/types/integer.rb', line 13 def expected_type_name "Integer" end |
#matches_type?(value) ⇒ Boolean
9 10 11 |
# File 'lib/rbdantic/validators/types/integer.rb', line 9 def matches_type?(value) value.is_a?(::Integer) end |