lib/barkick/gtin.rb in barkick-0.1.0 vs lib/barkick/gtin.rb in barkick-0.2.0
- old
+ new
@@ -244,16 +244,12 @@
if [7, 11, 12, 13].include?(number.length)
# https://www.gs1.org/barcodes/support/check_digit_calculator#how
digits = number.rjust(13, "0").split("").map(&:to_i)
# digit at position 0 is odd (first digit) for the purpose of this calculation
odd_digits, even_digits = digits.partition.each_with_index { |_digit, i| i.even? }
- ((10 - (sum(odd_digits) * 3 + sum(even_digits)) % 10) % 10).to_s
+ ((10 - (odd_digits.sum * 3 + even_digits.sum) % 10) % 10).to_s
else
nil
end
- end
-
- def self.sum(arr)
- arr.inject { |sum, x| sum + x }
end
end
end