class DailyAffirmation::Validators::NumericalityValidator
This affirmation ensures an attribute is a Number and if the :greater_than or :less_then option is given, that the attribute is greater than or less than the value provided.
@option opts [Numeric] :greater_than the value the attribute’s value must
be greater than.
@option opts [Numeric] :less_than the value the attribute’s value must be
less than.
Public Instance Methods
error_message()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 18 def error_message @error_message ||= i18n_error_message( :numericality, :default => default_error_message ) end
valid?()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 14 def valid? @valid ||= value ? numeric? && greater_than? && less_than? : true end
Private Instance Methods
default_error_message()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 46 def default_error_message numeric_error_message + greater_than_error_message + less_than_error_message end
greater_than?()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 30 def greater_than? @greater_than ||= if numeric? && gt = opts[:greater_than] value > gt else true end end
greater_than_error_message()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 55 def greater_than_error_message if greater_than? "" else " Must also be greater than #{opts[:greater_than]}." end end
less_than?()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 38 def less_than? @less_than ||= if numeric? && lt = opts[:less_than] value < lt else true end end
less_than_error_message()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 63 def less_than_error_message if less_than? "" else " Must also be less than #{opts[:less_than]}." end end
numeric?()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 26 def numeric? @numeric ||= value.is_a?(Numeric) end
numeric_error_message()
click to toggle source
# File lib/daily_affirmation/validators/numericality_validator.rb, line 51 def numeric_error_message "#{attribute} must be a number." end