lib/ibandit/local_details_cleaner.rb in ibandit-0.6.0 vs lib/ibandit/local_details_cleaner.rb in ibandit-0.6.1
- old
+ new
@@ -1,9 +1,9 @@
module Ibandit
module LocalDetailsCleaner
SUPPORTED_COUNTRY_CODES = %w(AT BE CY DE EE ES FI FR GB GR IE IT LT LU LV MC
- MT NL PT SE SI SK SM).freeze
+ MT NL NO PT 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)
@@ -27,11 +27,11 @@
def self.required_fields(country_code)
case country_code
when 'AT', 'CY', 'DE', 'FI', 'LT', 'LU', 'LV', 'NL', 'SI', 'SK'
%i(bank_code account_number)
- when 'BE', 'EE', 'ES', 'SE'
+ when 'BE', 'EE', 'ES', 'SE', 'NO'
%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
@@ -285,9 +285,28 @@
def self.clean_nl_details(local_details)
# Add leading zeros to account number if < 10 digits.
{
bank_code: local_details[:bank_code],
account_number: local_details[:account_number].rjust(10, '0')
+ }
+ end
+
+ def self.clean_no_details(local_details)
+ # This method supports being passed the component IBAN parts, as defined
+ # by SWIFT, or a single 11 digit string.
+ if local_details[:bank_code]
+ bank_code = local_details[:bank_code]
+ account_number = local_details[:account_number]
+ else
+ cleaned_acct_number = local_details[:account_number].gsub(/[-.\s]/, '')
+
+ bank_code = cleaned_acct_number.slice(0, 4)
+ account_number = cleaned_acct_number[4..-1]
+ end
+
+ {
+ bank_code: bank_code,
+ account_number: account_number
}
end
def self.clean_pt_details(local_details)
local_details