Class: Vindetta::Validator
- Inherits:
-
Object
- Object
- Vindetta::Validator
- Defined in:
- lib/vindetta/validator.rb
Constant Summary collapse
- LENGTH =
17- MAP =
"0123456789X".chars
- WEIGHTS =
"8765432X98765432".chars
Class Method Summary collapse
Class Method Details
.check_digit(vin) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vindetta/validator.rb', line 13 def self.check_digit(vin) wmi = Decoder.wmi(vin).chars vds = Decoder.vds(vin, :check_digit => false).chars vis = Decoder.vis(vin).chars calculated = [wmi, vds, vis].flatten.map.with_index do |c, i| Transliterator::run(c) * MAP.find_index(WEIGHTS[i]) end.sum MAP[calculated % 11] end |
.vin(vin) ⇒ Object
7 8 9 10 11 |
# File 'lib/vindetta/validator.rb', line 7 def self.vin(vin) return false unless vin.length == LENGTH check_digit(vin) == Decoder.check_digit(vin) end |