Class: VinValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- VinValidator
- Defined in:
- lib/vindicate/vin_validator.rb
Constant Summary collapse
- VALID_CHARS =
/[A-HJ-NPR-Z0-9]{17}/i
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vindicate/vin_validator.rb', line 4 def validate_each(record, attribute, value) 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 |