Module: Integer::NoBrainerExtensions
- Included in:
- Integer
- Defined in:
- lib/no_brainer/document/types/integer.rb
Constant Summary collapse
- InvalidType =
NoBrainer::Error::InvalidType
Instance Method Summary collapse
Instance Method Details
#nobrainer_cast_user_to_model(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/no_brainer/document/types/integer.rb', line 5 def nobrainer_cast_user_to_model(value) case value when Integer then value when String value = value.strip.gsub(/^\+/, '') value.to_i.tap { |new_value| new_value.to_s == value or raise InvalidType } when Float value.to_i.tap { |new_value| new_value.to_f == value or raise InvalidType } else raise InvalidType end end |