Sha256: 40d9a1da57dc9c796e7a90745e87423814f3bc1f517ec5faf573f448837abfcb

Contents?: true

Size: 1.02 KB

Versions: 16

Compression:

Stored size: 1.02 KB

Contents

class Ibanizator
  class Iban
    module ExtendedData
      class DE
        attr_reader :iban
        include Equalizer.new(:iban)
        include Adamantium

        def initialize(iban)
          raise Invalid, "can't compute extended data on invalid iban" unless iban.valid?
          @iban = iban
        end

        def bank_code
          iban.to_s[4..11]
        end
        memoize :bank_code

        def account_number
          iban.to_s[12..-1].gsub(/\A0+/,"")
        end
        memoize :account_number

        def bic
          bank.bic
        end

        def bank_name
          bank.name
        end

        def to_hash
          {
            bank_code: bank_code,
            account_number: account_number,
            bic: bic,
            bank_name: bank_name,
          }
        end
        alias_method :to_h, :to_hash

        private

        def bank
          Ibanizator.bank_db.bank_by_bank_code(bank_code)
        end
        memoize :bank
      end
    end # ExtendedData
  end # Iban
end # Ibanizator

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ibanizator-0.4.15 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.14 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.13 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.12 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.11 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.10 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.9 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.8 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.7 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.6 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.5 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.4 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.3 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.2 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.1 lib/ibanizator/iban/extended_data/de.rb
ibanizator-0.4.0 lib/ibanizator/iban/extended_data/de.rb