Created
September 13, 2017 10:20
-
-
Save oinak/cef57be2bf8438a95673371728a524cb to your computer and use it in GitHub Desktop.
Read info from iban_registry.txt
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
| # countries on sepa | |
| sepa = %w(AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IS IT LI LT LU LV | |
| MC MT NL NO PL PT RO SE SI SK SM) | |
| # config file from iso-iban gem | |
| file = File.read(File.join('data','iso-iban', 'specs.yaml')) | |
| config = YAML.load(file) | |
| # sepa countries with missing branch positions | |
| missing = config.select do |code, values| | |
| sepa.include?(code) && values[8].nil? | |
| end | |
| puts missing.keys.sort | |
| # => AT BE CH CZ DE DK EE FI FR GB HR IE IS LI LT LU LV NL NO PL RO SE SI SK | |
| # This 2 lines are copy-pasted from the tsv source with minimal text tranformations | |
| # https://www.swift.com/node/11971 | |
| codes=%w(AD AE AL AT AZ BA BE BG BH BR BY CH CR CY CZ DE DK DO EE ES FI FO FR | |
| GB GE GI GL GR GT HR HU IE IL IQ IS IT JO KW KZ LB LC LI LT LU LV MC | |
| MD ME MK MR MT MU NL NO PK PL PS PT QA RO RS SA SC SE SI SK SM ST SV | |
| TL TN TR UA VG XK) | |
| branch= ["5-8", nil, "4-8", nil, nil, "4-6", nil, "5-8", nil, "9-13", nil, nil, | |
| nil, "4-8", nil, nil, nil, nil, nil, "5-8", nil, nil, nil, "5-10", nil, | |
| nil, nil, "4-7", nil, nil, "4-7", "5-10", "4-6", "5-7", "3-4", "7-11", | |
| "5-8", nil, nil, nil, nil, nil, nil, nil, nil, "6-10", nil, nil, nil, | |
| "6-10", "5-9", "7-8", nil, nil, nil, "1-8", nil, nil, nil, nil, nil, | |
| nil, "7-8", nil, nil, nil, "7-11", "5-8", "1-4", nil, "3-5", nil, nil, | |
| nil, "3-4"] | |
| positions = codes.zip(branch) | |
| # Print all info available for countries without branch info | |
| missing.each do |k, v| | |
| new_info = positions.detect{|p| p[0] == k } | |
| puts "-#{new_info}-" | |
| end.size | |
| config.each do |k, v| | |
| new_info = positions.detect{|p| p[0] == k } | |
| if new_info && new_info.last && v.last.nil? | |
| a,b = new_info[1].split('-').map{|x| | |
| # +4 for country and check-digit ES99 XXXX XXXX XXXX XXXX | |
| # -1 beecause specs are 1-indexed (instead or 0) | |
| x.to_i + 3 | |
| } | |
| puts "-#{new_info}-#{v[6..-1].inspect} #{a} #{b}" | |
| end | |
| end.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment