ibandit 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -3
- data/README.md +3 -0
- data/bin/build_structure_file.rb +41 -5
- data/data/raw/structure_additions.yml +43 -0
- data/data/structures.yml +157 -0
- data/ibandit.gemspec +1 -1
- data/lib/ibandit/iban.rb +147 -60
- data/lib/ibandit/iban_assembler.rb +117 -0
- data/lib/ibandit/iban_splitter.rb +66 -0
- data/lib/ibandit/local_details_cleaner.rb +298 -0
- data/lib/ibandit/version.rb +1 -1
- data/lib/ibandit.rb +9 -1
- data/spec/ibandit/iban_assembler_spec.rb +567 -0
- data/spec/ibandit/iban_spec.rb +294 -13
- data/spec/ibandit/iban_splitter_spec.rb +41 -0
- data/spec/ibandit/local_details_cleaner_spec.rb +688 -0
- metadata +10 -6
- data/lib/ibandit/iban_builder.rb +0 -539
- data/spec/ibandit/iban_builder_spec.rb +0 -892
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: efe0d22849b9038cd0f8ba2d2a5ca9b73af14137
         | 
| 4 | 
            +
              data.tar.gz: dbf58fdc4ba8242d3676b76b01f194a5d58c4412
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 254642c61af11750bc56d04714521b778a34ac4f9852d65eb426ab50cd820c828a90efd180058e2c6b453a4745162ecc731aaf9e4cbcd2fccbe156017d042edb
         | 
| 7 | 
            +
              data.tar.gz: 1edbf221f87f7097760555697d26ec15bc7896906b3f63fd385c845f897cefebf17fa9dd74da3dff8e422e61004f3d132739f4a5e924c5cd4d14d5035c34e9f5
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,13 +1,20 @@ | |
| 1 | 
            -
            ## 0. | 
| 1 | 
            +
            ## 0.3.0 - February 6, 2015
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            - Move IBANBuilder interface into main IBAN class by overloading its constructor
         | 
| 4 | 
            +
            - Move validation of local details input out of IBANBuilder into IBAN
         | 
| 5 | 
            +
            - Split `IBAN.valid_length?` into individual checks on the length of bank code, branch code, and account number
         | 
| 6 | 
            +
            - Return `nil` for fields which aren't present, rather than an empty string
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## 0.2.1 - January 30, 2015
         | 
| 2 9 |  | 
| 3 10 | 
             
            - Add Lithuania to IBANBuilder
         | 
| 4 11 |  | 
| 5 | 
            -
            ## 0.2.0 - January 27,  | 
| 12 | 
            +
            ## 0.2.0 - January 27, 2015
         | 
| 6 13 |  | 
| 7 14 | 
             
            - Add GermanDetailsConverter
         | 
| 8 15 |  | 
| 9 16 |  | 
| 10 | 
            -
            ## 0.1.1 - January 8,  | 
| 17 | 
            +
            ## 0.1.1 - January 8, 2015
         | 
| 11 18 |  | 
| 12 19 | 
             
            - Add zero-padding to CheckDigit.spanish
         | 
| 13 20 |  | 
    
        data/README.md
    CHANGED
    
    
    
        data/bin/build_structure_file.rb
    CHANGED
    
    | @@ -37,21 +37,57 @@ def get_iban_structures(iban_structures_file, iban_registry_file) | |
| 37 37 | 
             
                  account_number_position: country.account_number_position.to_i,
         | 
| 38 38 | 
             
                  account_number_length: country.account_number_length.to_i,
         | 
| 39 39 | 
             
                  total_length: country.total_length.to_i,
         | 
| 40 | 
            -
                  iban_national_id_length: country.iban_national_id_length.to_i | 
| 41 | 
            -
             | 
| 42 | 
            -
                }
         | 
| 40 | 
            +
                  iban_national_id_length: country.iban_national_id_length.to_i
         | 
| 41 | 
            +
                }.merge(bban_formats[country.country_code])
         | 
| 43 42 | 
             
              end
         | 
| 44 43 | 
             
            end
         | 
| 45 44 |  | 
| 46 45 | 
             
            def get_bban_formats(iban_registry_file)
         | 
| 47 46 | 
             
              iban_registry_file.each_with_object({}) do |line, hash|
         | 
| 48 47 | 
             
                bban_structure = line['BBAN structure '].strip
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                bank_code_structure, branch_code_structure =
         | 
| 50 | 
            +
                  if line['Bank identifier length']
         | 
| 51 | 
            +
                    line['Bank identifier length'].split(/, Branch identifier length:? /)
         | 
| 52 | 
            +
                  else
         | 
| 53 | 
            +
                    ['', nil]
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
             | 
| 49 56 | 
             
                country_code = line['Country code as defined in ISO 3166'].strip
         | 
| 50 | 
            -
                hash[country_code] = convert_swift_convention(bban_structure | 
| 57 | 
            +
                hash[country_code] = convert_swift_convention(bban_structure,
         | 
| 58 | 
            +
                                                              bank_code_structure,
         | 
| 59 | 
            +
                                                              branch_code_structure)
         | 
| 51 60 | 
             
              end
         | 
| 52 61 | 
             
            end
         | 
| 53 62 |  | 
| 54 | 
            -
             | 
| 63 | 
            +
            # IBAN Registry has BBAN format (which seems to be accurate), and Bank
         | 
| 64 | 
            +
            # identifier length, which contains something roughly like the format for the
         | 
| 65 | 
            +
            # bank code and usually the branch code where applicable. This is a best attempt
         | 
| 66 | 
            +
            # to convert those from weird SWIFT-talk into regexes, and then work out the
         | 
| 67 | 
            +
            # account number format regex by taking the bank and branch code regexes off
         | 
| 68 | 
            +
            # the front of the BBAN format.
         | 
| 69 | 
            +
            #
         | 
| 70 | 
            +
            # This works about 70% of the time, the rest are overridden in
         | 
| 71 | 
            +
            # structure_additions.yml
         | 
| 72 | 
            +
            def convert_swift_convention(bban, bank, branch)
         | 
| 73 | 
            +
              bban_regex = iban_registry_to_regex(bban)
         | 
| 74 | 
            +
              bank_regex = iban_registry_to_regex(bank)
         | 
| 75 | 
            +
              branch_regex = branch.nil? ? nil : iban_registry_to_regex(branch)
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              non_account_number_regex = [bank_regex, branch_regex].join
         | 
| 78 | 
            +
              account_number_start = (bban_regex.index(non_account_number_regex) || 0) +
         | 
| 79 | 
            +
                                     non_account_number_regex.length
         | 
| 80 | 
            +
              account_number_regex = bban_regex[account_number_start..-1]
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              {
         | 
| 83 | 
            +
                bban_format:           bban_regex,
         | 
| 84 | 
            +
                bank_code_format:      bank_regex,
         | 
| 85 | 
            +
                branch_code_format:    branch_regex,
         | 
| 86 | 
            +
                account_number_format: account_number_regex
         | 
| 87 | 
            +
              }.reject { |_, value| value.nil? }
         | 
| 88 | 
            +
            end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
            def iban_registry_to_regex(swift_string)
         | 
| 55 91 | 
             
              swift_string.gsub(/(\d+)!([nac])/, '\2{\1}').
         | 
| 56 92 | 
             
                gsub('n', '\d').
         | 
| 57 93 | 
             
                gsub('a', '[A-Z]').
         | 
| @@ -1,10 +1,23 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            +
            AL:
         | 
| 3 | 
            +
              :bank_code_format: \d{3}
         | 
| 4 | 
            +
              :branch_code_format: \d{5}
         | 
| 5 | 
            +
            BR:
         | 
| 6 | 
            +
              :bank_code_format: \d{8}
         | 
| 7 | 
            +
              :branch_code_format: \d{5}
         | 
| 8 | 
            +
              :account_number_format: '\d{10}[A-Z]{1}[A-Z0-9]{1}'
         | 
| 2 9 | 
             
            BE:
         | 
| 3 10 | 
             
              :local_check_digit_position: 15
         | 
| 4 11 | 
             
              :local_check_digit_length: 2
         | 
| 12 | 
            +
            BH:
         | 
| 13 | 
            +
              :bank_code_format: '[A-Z]{4}'
         | 
| 14 | 
            +
              :account_number_format: '[A-Z0-9]{14}'
         | 
| 5 15 | 
             
            DE:
         | 
| 6 16 | 
             
              :bban_format: \d{8}\d{10}
         | 
| 17 | 
            +
              :account_number_format: \d{10}
         | 
| 7 18 | 
             
            EE:
         | 
| 19 | 
            +
              :bank_code_format: '[1-9][0-9]'
         | 
| 20 | 
            +
              :account_number_format: \d{2}\d{11}\d{1}
         | 
| 8 21 | 
             
              :local_check_digit_position: 20
         | 
| 9 22 | 
             
              :local_check_digit_length: 1
         | 
| 10 23 | 
             
            ES:
         | 
| @@ -12,31 +25,61 @@ ES: | |
| 12 25 | 
             
              :local_check_digit_length: 2
         | 
| 13 26 | 
             
            FI:
         | 
| 14 27 | 
             
              :bban_format: \d{6}\d{7}\d{1}
         | 
| 28 | 
            +
              :bank_code_format: \d{6}
         | 
| 29 | 
            +
              :account_number_format: \d{7}\d{1}
         | 
| 15 30 | 
             
              :local_check_digit_position: 18
         | 
| 16 31 | 
             
              :local_check_digit_length: 1
         | 
| 17 32 | 
             
            FR:
         | 
| 33 | 
            +
              :branch_code_format: \d{5}
         | 
| 34 | 
            +
              :account_number_format: '[A-Z0-9]{11}\d{2}'
         | 
| 18 35 | 
             
              :local_check_digit_position: 26
         | 
| 19 36 | 
             
              :local_check_digit_length: 2
         | 
| 37 | 
            +
            GB:
         | 
| 38 | 
            +
              :branch_code_format: \d{6}
         | 
| 39 | 
            +
              :account_number_format: \d{8}
         | 
| 20 40 | 
             
            HU:
         | 
| 21 41 | 
             
              :bban_format: \d{3}\d{4}\d{1}\d{15}\d{1}
         | 
| 42 | 
            +
              :account_number_format: \d{1}\d{15}\d{1}
         | 
| 22 43 | 
             
            IT:
         | 
| 23 44 | 
             
              :local_check_digit_position: 5
         | 
| 24 45 | 
             
              :local_check_digit_length: 1
         | 
| 46 | 
            +
            LB:
         | 
| 47 | 
            +
              :bban_format: \d{4}[A-Z0-9]{20}
         | 
| 48 | 
            +
              :bank_code_format: \d{4}
         | 
| 49 | 
            +
              :account_number_format: '[A-Z0-9]{14}'
         | 
| 25 50 | 
             
            MC:
         | 
| 26 51 | 
             
              :local_check_digit_position: 26
         | 
| 27 52 | 
             
              :local_check_digit_length: 2
         | 
| 53 | 
            +
            MU:
         | 
| 54 | 
            +
              :bban_format: '[A-Z]{4}\d{2}\d{2}\d{12}\d{3}[A-Z]{3}'
         | 
| 55 | 
            +
              :bank_code_format: '[A-Z]{4}\d{2}'
         | 
| 56 | 
            +
              :branch_code_format: \d{2}
         | 
| 57 | 
            +
              :account_number_format: '\d{12}\d{3}[A-Z]{3}'
         | 
| 28 58 | 
             
            NL:
         | 
| 29 59 | 
             
              :local_check_digit_position: 18
         | 
| 30 60 | 
             
              :local_check_digit_length: 1
         | 
| 31 61 | 
             
            PT:
         | 
| 62 | 
            +
              :branch_code_format: \d{4}
         | 
| 63 | 
            +
              :account_number_format: \d{11}\d{2}
         | 
| 32 64 | 
             
              :local_check_digit_position: 24
         | 
| 33 65 | 
             
              :local_check_digit_length: 2
         | 
| 34 66 | 
             
            QA:
         | 
| 35 67 | 
             
              :bban_format: '[A-Z]{4}[A-Z0-9]{21}'
         | 
| 68 | 
            +
              :bank_code_format: '[A-Z]{4}'
         | 
| 69 | 
            +
              :account_number_format: '[A-Z0-9]{21}'
         | 
| 70 | 
            +
            SA:
         | 
| 71 | 
            +
              :bank_code_format: \d{2}
         | 
| 72 | 
            +
              :account_number_format: '[A-Z0-9]{18}'
         | 
| 73 | 
            +
            SI:
         | 
| 74 | 
            +
              :bank_code_format: \d{5}
         | 
| 75 | 
            +
              :account_number_format: \d{8}\d{2}
         | 
| 36 76 | 
             
            SK:
         | 
| 37 77 | 
             
              :local_check_digit_position: 14
         | 
| 38 78 | 
             
              :local_check_digit_length: 1
         | 
| 39 79 | 
             
            SM:
         | 
| 80 | 
            +
              :bank_code_format: \d{5}
         | 
| 81 | 
            +
              :branch_code_format: \d{5}
         | 
| 82 | 
            +
              :account_number_format: '[A-Z0-9]{12}'
         | 
| 40 83 | 
             
              :local_check_digit_position: 5
         | 
| 41 84 | 
             
              :local_check_digit_length: 1
         | 
| 42 85 | 
             
            TL:
         |