4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/vindicate/vin_validator.rb', line 4
def validate_each(record, attribute, value)
return if value.blank?
unless value.respond_to?(:length)
record.errors[attribute] << 'is invalid'
return
end
if value.length < 17
record.errors[attribute] << 'is too short'
return
end
if value.length > 17
record.errors[attribute] << 'is too long'
return
end
unless value =~ VALID_CHARS
record.errors[attribute] << 'contains invalid characters'
return
end
record.errors[attribute] << 'is invalid' unless valid?(value)
end
|