Sha256: 61a31248f4ffebc6750ce19b5139477c31d0c4e6e9964dd061a6ca0b6a95be78
Contents?: true
Size: 989 Bytes
Versions: 4
Compression:
Stored size: 989 Bytes
Contents
# frozen_string_literal: true require 'yaml' require 'errors/bank_not_found' require 'errors/unsupported_country' class PolishBank attr_reader :name, :branch 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 attr_reader :iban def account_number iban.to_s.tr('^0-9', '') end def bank_identifier account_number[2..5].to_i end def country_code iban.to_s[0..1] end def check_country return if integer?(country_code) raise UnsupportedCountry, "Iban #{iban} is not Polish" if country_code.casecmp('PL') != 0 end def full_identifier account_number[2..9].to_i end def integer?(string) Integer(string) rescue ArgumentError false end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
polish_banks-1.1.3 | lib/polish_banks.rb |
polish_banks-1.1.2 | lib/polish_banks.rb |
polish_banks-1.1.1 | lib/polish_banks.rb |
polish_banks-1.1.0 | lib/polish_banks.rb |