lib/ibandit/iban_assembler.rb in ibandit-0.11.6 vs lib/ibandit/iban_assembler.rb in ibandit-0.11.7

- old
+ new

@@ -1,8 +1,8 @@ module Ibandit module IBANAssembler - EXCEPTION_COUNTRY_CODES = %w(IT SM BE).freeze + EXCEPTION_COUNTRY_CODES = %w[IT SM BE].freeze def self.assemble(local_details) country_code = local_details[:country_code] return unless can_assemble?(local_details) @@ -45,11 +45,11 @@ # elements, so should be passed explicitly or left blank for it to be # calculated implicitly partial_bban = [ opts[:bank_code], opts[:branch_code], - opts[:account_number] + opts[:account_number], ].join check_digit = opts[:check_digit] || CheckDigit.italian(partial_bban) [check_digit, partial_bban].join @@ -67,11 +67,12 @@ def self.can_assemble?(local_details) supported_country_code?(local_details) && valid_arguments?(local_details) end def self.supported_country_code?(local_details) - Constants::SUPPORTED_COUNTRY_CODES.include?(local_details[:country_code]) + Constants::CONSTRUCTABLE_IBAN_COUNTRY_CODES. + include?(local_details[:country_code]) end def self.valid_arguments?(local_details) country_code = local_details[:country_code] @@ -84,34 +85,35 @@ supplied.all? { |key| allowed.include?(key) } end def self.required_fields(country_code) case country_code - when *%w(AT CY CZ DE DK EE FI HR IS LT LU LV NL NO PL RO SE SI SK) - %i(bank_code account_number) - when 'BE' - %i(account_number) + when "AT", "CY", "CZ", "DE", "DK", "EE", "FI", "HR", "IS", "LT", "LU", + "LV", "NL", "NO", "PL", "RO", "SE", "SI", "SK" + %i[bank_code account_number] + when "BE" + %i[account_number] else - %i(bank_code branch_code account_number) + %i[bank_code branch_code account_number] end end def self.allowed_fields(country_code) # Some countries have additional optional fields case country_code - when 'BE' then %i(bank_code account_number) - when 'CY' then %i(bank_code branch_code account_number) - when 'IT' then %i(bank_code branch_code account_number check_digit) - when 'CZ', 'SK' then %i(bank_code account_number account_number_prefix) + when "BE" then %i[bank_code account_number] + when "CY" then %i[bank_code branch_code account_number] + when "IT" then %i[bank_code branch_code account_number check_digit] + when "CZ", "SK" then %i[bank_code account_number account_number_prefix] else required_fields(country_code) end end def self.assemble_iban(country_code, bban) [ country_code, CheckDigit.iban(country_code, bban), - bban + bban, ].join rescue InvalidCharacterError nil end end