Sha256: 65150e69ede0a07d95ef35c423879931bd0312e94936e126d6837e0eac96baad

Contents?: true

Size: 397 Bytes

Versions: 1

Compression:

Stored size: 397 Bytes

Contents

module Vindetta
  class Calculator
    CHECK_DIGITS = "0123456789X".chars
    WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]

    def self.check_digit(vin)
      CHECK_DIGITS[sum(vin) % CHECK_DIGITS.length]
    end

    private

    def self.sum(vin)
      Transliterator
        .vin(vin)
        .zip(WEIGHTS)
        .reduce(0) { |sum, (a, b)| sum + (a * b) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vindetta-0.19.0 lib/vindetta/calculator.rb