class StandaloneValidator::NamedValidations::ValidatesNumericalityOf
Constants
- COMPARISON_OPTIONS
- INTEGER_REGEX
Stolen from ActiveSupport
Private Instance Methods
coerce_to_number(value)
click to toggle source
# File lib/standalone_validator/named_validations/validates_numericality_of.rb, line 67 def coerce_to_number(value) if options[:only_integer] raise ArgumentError unless value.to_s =~ INTEGER_REGEX Kernel.Integer(value) else Kernel.Float(value) end end
each_comparison_violation_of(value) { |option, base| ... }
click to toggle source
# File lib/standalone_validator/named_validations/validates_numericality_of.rb, line 50 def each_comparison_violation_of(value) selected_comparisons.each do |option, (base, check)| yield(option, base) unless check.call(base, value) end self end
ignore_value?(value)
click to toggle source
# File lib/standalone_validator/named_validations/validates_numericality_of.rb, line 40 def ignore_value?(value) if options[:allow_nil] value.nil? elsif options[:allow_blank] value.blank? else false end end
selected_comparisons()
click to toggle source
# File lib/standalone_validator/named_validations/validates_numericality_of.rb, line 58 def selected_comparisons return @selected_comparisons if defined?(@selected_comparisons) passed = COMPARISON_OPTIONS.keys & options.keys @selected_comparisons = passed.each_with_object({}) do |option, result| result[option] = [options[option], COMPARISON_OPTIONS[option]] end end