Last active
October 25, 2019 13:56
-
-
Save rivsc/f8c74f32a24958efb7b6a0c4447a774e to your computer and use it in GitHub Desktop.
Méthode de calcul de la clé RIB (relevé d'identité bancaire)
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
# Methode de calcul de la clé RIB (relevé d'identité bancaire) | |
# le calcul vient de wikipedia fr | |
def cle_rib(code_banque, code_guichet, numero_compte) | |
mapping = ["", "AJ", "BKS", "CLT", "DMU", "ENV", "FOW", "GPX", "HQY", "IRZ"] | |
numero_compte.scan(/[A-Z]/).each do |ch| | |
mapping.each_with_index do |str, i| | |
if str.include?(ch) | |
numero_compte = numero_compte.gsub(ch, i.to_s) | |
break | |
end | |
end | |
end | |
97 - ((89 * code_banque.to_i + 15 * code_guichet.to_i + 76 * numero_compte[0..5].to_i + 3 * numero_compte[6..-1].to_i) % 97) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment