Skip to content

Instantly share code, notes, and snippets.

@anarchivist
Created April 23, 2009 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anarchivist/100757 to your computer and use it in GitHub Desktop.
Save anarchivist/100757 to your computer and use it in GitHub Desktop.
calculate III record number check digits
# 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