Created
August 24, 2011 07:17
-
-
Save KarlHerler/1167467 to your computer and use it in GitHub Desktop.
Calculating finnish banking reference numbers (Viitenumerot) in ruby
This file contains hidden or 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 refnr(source) | |
#this takes a ID string with number but declared as string and returns a valid reference number | |
chk = 0 #the integrity check number | |
weights = [7, 3, 1] #hash weights, declared by THE GOVERNMENT | |
source.split('').reverse.each_with_index { |x, i| chk += (x.to_i)*weights[i%3] } #does the caluclation | |
return "#{source}#{((10-(chk%10))%10)}" #returns the input number with the check number trailing it | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment