class IbanCalculator::IbanValidatorResponse

Constants

CHECKS

Attributes

raw_response[RW]

Public Class Methods

new(raw_response) click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 12
def initialize(raw_response)
  self.raw_response = raw_response
end

Public Instance Methods

account_number() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 41
def account_number
  @account_number ||= string_or_default(raw_response[:account_number], nil)
end
as_json(opts = {}) click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 61
def as_json(opts = {})
  {
    valid: valid?,
    errors: errors,
    account_number: account_number,
    bank: bank.name,
    bank_code: bank.code,
    bics: bic_candidates.map { |c| c.as_json(opts) },
    updated_at: updated_at,
    checks: checks,
  }.deep_stringify_keys!
end
bank() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 28
def bank
  @bank ||= begin Bank.new({
      code: string_or_default(raw_response[:bank_code]),
      name: string_or_default(raw_response[:bank]),
      country: string_or_default(raw_response[:country]),
      address: string_or_default(raw_response[:bank_address]).strip,
      url: string_or_default(raw_response[:bank_url]),
      branch: string_or_default(raw_response[:branch]),
      branch_code: string_or_default(raw_response[:branch_code]),
    })
  end
end
bic_candidates() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 24
def bic_candidates
  @bic_candidates ||= BicCandidate.build_list(raw_response[:bic_candidates])
end
checks() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 45
def checks
  CHECKS.each_with_object({}) do |(app_key, api_key), result|
    result[app_key] = string_or_default(raw_response[api_key], 'not_checked')
  end
end
errors() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 57
def errors
  @errors ||= InvalidData.new('', return_code).errors
end
return_code() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 20
def return_code
  @return_code ||= raw_response[:return_code].to_i
end
updated_at() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 51
def updated_at
  @data_created_at ||= Date.parse(raw_response[:data_age]) if string_or_default(raw_response[:data_age], nil)
rescue ArgumentError
  nil
end
valid?() click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 16
def valid?
  return_code < 128
end

Private Instance Methods

string_or_default(input, default = '') click to toggle source
# File lib/iban_calculator/iban_validator_response.rb, line 76
def string_or_default(input, default = '')
  input.kind_of?(String) ? input : default
end