lib/validations/validates_numericality_of.rb in validatable-1.2.2 vs lib/validations/validates_numericality_of.rb in validatable-1.3.0

- old
+ new

@@ -1,9 +1,12 @@ module Validatable class ValidatesNumericalityOf < ValidationBase #:nodoc: - + option :only_integer + def valid?(instance) - not (instance.send(self.attribute).to_s =~ /^\d*\.{0,1}\d+$/).nil? + value = instance.send(self.attribute).to_s + regex = self.only_integer ? /\A[+-]?\d+\Z/ : /^\d*\.{0,1}\d+$/ + not (value =~ regex).nil? end def message super || "must be a number" end