lib/vindetta/calculator.rb in vindetta-0.17.1 vs lib/vindetta/calculator.rb in vindetta-0.19.0

- old
+ new

@@ -1,15 +1,19 @@ module Vindetta class Calculator - MAP = %w(0 1 2 3 4 5 6 7 8 9 X) + 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) - sum = Transliterator + 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) } - - MAP[sum % 11] + .reduce(0) { |sum, (a, b)| sum + (a * b) } end end end