class AdLint::Validation::NumericalityValidator
Public Class Methods
new(attr_name, only_int, min, max)
click to toggle source
Calls superclass method
AdLint::Validation::Validator::new
# File lib/adlint/util.rb, line 222 def initialize(attr_name, only_int, min, max) super(attr_name) @only_integer = only_int @min = min @max = max end
Public Instance Methods
execute(attr_owner)
click to toggle source
Calls superclass method
AdLint::Validation::PresenceValidator#execute
# File lib/adlint/util.rb, line 229 def execute(attr_owner) return false unless super val = target_value(attr_owner) case val when Numeric if @only_integer && !val.integer? @errors.push("`#{qualified_attr_name(attr_owner)}' " + "is not an integer.") return false end if @min && val < @min @errors.push("`#{qualified_attr_name(attr_owner)}' " + "is not greater than or equal to #{@min}.") return false end if @max && @max < val @errors.push("`#{qualified_attr_name(attr_owner)}' " + "is not less than or equal to #{@max}.") return false end else @errors.push("`#{qualified_attr_name(attr_owner)}' " + "is not a numerical value.") return false end true end