class PolishBank

Attributes

branch[R]
iban[R]
name[R]

Public Class Methods

new(iban) click to toggle source
# File lib/polish_banks.rb, line 10
def initialize(iban)
  @iban = iban
  check_country
  data = YAML.load_file(File.join(File.dirname(__FILE__), 'data', "#{bank_identifier}.yml"))
  @name = data.dig('name')
  @branch = data.dig(full_identifier, 'branch') || ''
rescue Errno::ENOENT
  raise BankNotFound, "Polish bank not found for #{iban}"
end

Private Instance Methods

account_number() click to toggle source
# File lib/polish_banks.rb, line 24
def account_number
  iban.to_s.tr('^0-9', '')
end
bank_identifier() click to toggle source
# File lib/polish_banks.rb, line 28
def bank_identifier
  account_number[2..5].to_i
end
check_country() click to toggle source
# File lib/polish_banks.rb, line 36
def check_country
  return if integer?(country_code)

  raise UnsupportedCountry, "Iban #{iban} is not Polish" if country_code.casecmp('PL') != 0
end
country_code() click to toggle source
# File lib/polish_banks.rb, line 32
def country_code
  iban.to_s[0..1]
end
full_identifier() click to toggle source
# File lib/polish_banks.rb, line 42
def full_identifier
  account_number[2..9].to_i
end
integer?(string) click to toggle source
# File lib/polish_banks.rb, line 46
def integer?(string)
  Integer(string)
rescue ArgumentError
  false
end