lib/ibandit/local_details_cleaner.rb in ibandit-0.6.4 vs lib/ibandit/local_details_cleaner.rb in ibandit-0.6.5

- old
+ new

@@ -1,9 +1,10 @@ module Ibandit module LocalDetailsCleaner - SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE DK EE ES FI FR GB GR IE IS IT LT LU - LV MC MT NL NO PL PT SE SI SK SM).freeze + SUPPORTED_COUNTRY_CODES = %w(AT BE BG CY DE DK EE ES FI FR GB GR HU IE IS IT + LT LU LV MC MT NL NO PL PT RO SE SI SK + SM).freeze def self.clean(local_details) country_code = local_details[:country_code] return local_details unless can_clean?(country_code, local_details) @@ -25,13 +26,13 @@ required_fields(country_code).all? { |argument| opts[argument] } end def self.required_fields(country_code) case country_code - when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'SI', 'SK' + when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'RO', 'SI', 'SK' %i(bank_code account_number) - when 'BE', 'DK', 'EE', 'ES', 'SE', 'NO', 'PL', 'IS' + when 'BE', 'DK', 'EE', 'ES', 'HU', 'IS', 'NO', 'PL', 'SE' %i(account_number) when 'GB', 'IE', 'MT' if Ibandit.bic_finder.nil? then %i(bank_code branch_code account_number) else %i(branch_code account_number) end @@ -61,10 +62,15 @@ bank_code: local_details[:bank_code] || account_number.slice(0, 3), account_number: account_number } end + def self.clean_bg_details(local_details) + # Bulgarian national bank details were replaced with IBANs in 2006. + local_details + end + def self.clean_cy_details(local_details) # Account number may be 7-16 digits long. # Add leading zeros to account number if < 16 digits. cleaned_bank_code = local_details[:bank_code].gsub(/[-\s]/, '') @@ -225,10 +231,36 @@ # Greek IBANs construction is idiosyncratic to the individual banks, and # no central specification is published. local_details end + def self.clean_hu_details(local_details) + # This method supports being passed the component IBAN parts, as defined + # by SWIFT, or a single 16 or 24 digit string. + if local_details[:bank_code] || local_details[:branch_code] + return local_details + end + + cleaned_acct_number = local_details[:account_number].gsub(/[-\s]/, '') + + case cleaned_acct_number.length + when 16 + { + bank_code: cleaned_acct_number.slice(0, 3), + branch_code: cleaned_acct_number.slice(3, 4), + account_number: cleaned_acct_number.slice(7, 9).ljust(17, '0') + } + when 24 + { + bank_code: cleaned_acct_number.slice(0, 3), + branch_code: cleaned_acct_number.slice(3, 4), + account_number: cleaned_acct_number.slice(7, 17) + } + else local_details + end + end + def self.clean_ie_details(local_details) # Ireland uses the same local details as the United Kingdom branch_code = local_details[:branch_code].gsub(/[-\s]/, '') if local_details[:bank_code] @@ -360,9 +392,14 @@ account_number: account_number } end def self.clean_pt_details(local_details) + local_details + end + + def self.clean_ro_details(local_details) + # Romanian national bank details were replaced with IBANs in 2004. local_details end def self.clean_se_details(local_details) converted_details =