Class: Validatable::ValidatesNumericalityOf
- Inherits:
-
ValidationBase
- Object
- ValidationBase
- Validatable::ValidatesNumericalityOf
- Defined in:
- lib/validations/validates_numericality_of.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from ValidationBase
Instance Method Summary collapse
Methods inherited from ValidationBase
after_validate, after_validations, all_after_validations, all_defaults, default, defaults, #initialize, option, #raise_error_if_key_is_dup, required_option, #run_after_validate, #should_validate?, #validate_this_time?
Methods included from Requireable
Methods included from Understandable
Constructor Details
This class inherits a constructor from Validatable::ValidationBase
Instance Method Details
#message(instance) ⇒ Object
11 12 13 |
# File 'lib/validations/validates_numericality_of.rb', line 11 def (instance) super || "must be a number" end |
#valid?(instance) ⇒ Boolean
5 6 7 8 9 |
# File 'lib/validations/validates_numericality_of.rb', line 5 def valid?(instance) value = instance.send(self.attribute).to_s regex = self.only_integer ? /\A[+-]?\d+\Z/ : /^\d*\.{0,1}\d+$/ not (value =~ regex).nil? end |