Created
April 23, 2009 20:50
-
-
Save anarchivist/100757 to your computer and use it in GitHub Desktop.
calculate III record number check digits
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
# take an string w/ an iii record number without recordtype prefix | |
# and without check digit and calculate its check digit | |
def calc_check_digit(digits) | |
digit_seq = digits.split.reverse | |
sum = 0 | |
multiplier = 2 | |
digit_seq.each { |digit| | |
sum += digit.to_i * multiplier | |
multiplier += 1 | |
} | |
cdig = sum % 11 | |
if cdig == 10: | |
'x' | |
else | |
cdig.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment