Class: Unidom::ArticleNumber::VehicleIdentificationNumberValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Unidom::ArticleNumber::VehicleIdentificationNumberValidator
- Defined in:
- app/validators/unidom/article_number/vehicle_identification_number_validator.rb
Constant Summary collapse
- WEIGHTS =
'8765432X098765432'.freeze
- TRANSLITERATION =
'0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ'.freeze
- CHECK_DIGITS =
'0123456789X'.freeze
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/validators/unidom/article_number/vehicle_identification_number_validator.rb', line 13 def validate_each(record, attribute, value) value = value.to_s.upcase if value.length>17 record.errors[attribute] << ([:message]||'The length should be 17') elsif value.match /I|O|Q/ record.errors[attribute] << ([:message]||'I, O, Q should be excluded') else record.errors[attribute] << ([:message]||'is invalid') unless check_digit(value)==value[8] end end |