Class: Israeli::BankAccountResult

Inherits:
Result
  • Object
show all
Defined in:
lib/israeli/result.rb

Overview

Result object for bank account validation with format detection.

Instance Attribute Summary collapse

Attributes inherited from Result

#normalized, #original, #reason

Instance Method Summary collapse

Methods inherited from Result

#invalid?, #to_s, #valid?, #value

Constructor Details

#initialize(original:, normalized:, valid:, reason: nil, format: nil) ⇒ BankAccountResult

Returns a new instance of BankAccountResult.

Parameters:

  • format (Symbol, nil) (defaults to: nil)

    Detected format (:domestic or :iban)



126
127
128
129
# File 'lib/israeli/result.rb', line 126

def initialize(original:, normalized:, valid:, reason: nil, format: nil)
  super(original: original, normalized: normalized, valid: valid, reason: reason)
  @format = format
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



123
124
125
# File 'lib/israeli/result.rb', line 123

def format
  @format
end

Instance Method Details

#domestic?Boolean

Returns true if this is a domestic account.

Returns:

  • (Boolean)

    true if this is a domestic account



132
133
134
# File 'lib/israeli/result.rb', line 132

def domestic?
  format == :domestic
end

#formatted(style: :domestic) ⇒ String?

Format the bank account.

Parameters:

  • style (Symbol) (defaults to: :domestic)

    :domestic, :compact, or :iban

Returns:

  • (String, nil)

    Formatted bank account or nil if invalid



145
146
147
148
149
# File 'lib/israeli/result.rb', line 145

def formatted(style: :domestic)
  return nil unless valid?

  Validators::BankAccount.format(@original, style: style)
end

#iban?Boolean

Returns true if this is an IBAN.

Returns:

  • (Boolean)

    true if this is an IBAN



137
138
139
# File 'lib/israeli/result.rb', line 137

def iban?
  format == :iban
end