モジュラス10ウェイト3の計算方法に関しては、以下をご確認ください。
http://www.barcode-net.com/chisiki/modulus10_3.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_modulus10(v) | |
val = v.reverse | |
pos = total_even = total_odd = 0 | |
val.split(//).each do |d| | |
pos = pos + 1 | |
(pos % 2) == 0 ? total_even += d.to_i : total_odd += d.to_i | |
end | |
digit = 10 - (total_even + total_odd * 3).to_s[-1,1].to_i | |
digit = 0 if digit == 10 | |
return digit.to_s | |
end |