Sha256: 6a1087577fd389366d35f8e01758bc4fe3a9d15eff97b2472a129749c4d584a2
Contents?: true
Size: 453 Bytes
Versions: 3
Compression:
Stored size: 453 Bytes
Contents
module Vindetta class Calculator def self.check_digit(vin) transliterator = -> (c) do "0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ".chars.index(c) % 10 end summer = -> (sum, (a, b)) do sum + (a * b) end sum = vin .chars .map(&transliterator) .zip([8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]) .reduce(0, &summer) "0123456789X"[sum % 11] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
vindetta-0.22.0 | lib/vindetta/calculator.rb |
vindetta-0.21.0 | lib/vindetta/calculator.rb |
vindetta-0.20.0 | lib/vindetta/calculator.rb |