Sha256: b23239bf4e5d4d9cfc41512a784962f8b16068105cae767eec71387fbc4773a0

Contents?: true

Size: 954 Bytes

Versions: 16

Compression:

Stored size: 954 Bytes

Contents

require 'equalizer'
require 'adamantium'

require_relative 'iban/extended_data'
require_relative 'iban/lengths'
require_relative 'iban/validator'

class Ibanizator
  class Iban
    attr_reader :iban_string
    alias_method :to_s, :iban_string

    include Equalizer.new(:iban_string)
    include Adamantium

    def initialize(an_iban)
      @iban_string = sanitize(an_iban)
    end

    def self.from_string(a_string)
      new(a_string)
    end

    def country_code
      cc = iban_string[0..1].to_sym
      LENGTHS.keys.include?(cc) ? cc : :unknown
    end
    memoize :country_code

    def extended_data
      if country_code == :DE
        ExtendedData::DE.new(self)
      end
    end
    memoize :extended_data

    def valid?
      Validator.new(self).validate
    end

    def formatted_iban_string
      iban_string.scan(/.{1,4}/).join(' ')
    end

    private
    def sanitize(input)
      input.to_s.gsub(/\s+/,'').upcase
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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