class ValidIntValidator
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/brita/validators/valid_int_validator.rb, line 2 def validate_each(record, attribute, value) record.errors.add attribute, (options[:message] || "must be integer, array of integers, or range") unless valid_int?(value) end
Private Instance Methods
integer_array?(value)
click to toggle source
# File lib/brita/validators/valid_int_validator.rb, line 13 def integer_array?(value) if value.is_a?(String) value = Brita::ValueParser.new(value: value).array_from_json end value.is_a?(Array) && value.any? && value.all? { |v| integer_or_range?(v) } end
integer_or_range?(value)
click to toggle source
# File lib/brita/validators/valid_int_validator.rb, line 21 def integer_or_range?(value) !!(/\A\d+(...\d+)?\z/ =~ value.to_s) end
valid_int?(value)
click to toggle source
# File lib/brita/validators/valid_int_validator.rb, line 9 def valid_int?(value) integer_array?(value) || integer_or_range?(value) end