Class: IbanCalculator::IbanValidatorResponse
- Inherits:
-
Object
- Object
- IbanCalculator::IbanValidatorResponse
- Defined in:
- lib/iban_calculator/iban_validator_response.rb
Constant Summary collapse
- CHECKS =
{ length: :length_check, account_number: :account_check, bank_code: :bank_code_check, iban_checksum: :iban_checksum_check, }
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
Instance Method Summary collapse
- #account_number ⇒ Object
- #as_json(opts = {}) ⇒ Object
- #bank ⇒ Object
- #bic_candidates ⇒ Object
- #checks ⇒ Object
- #errors ⇒ Object
-
#initialize(raw_response) ⇒ IbanValidatorResponse
constructor
A new instance of IbanValidatorResponse.
- #return_code ⇒ Object
- #updated_at ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(raw_response) ⇒ IbanValidatorResponse
Returns a new instance of IbanValidatorResponse.
12 13 14 |
# File 'lib/iban_calculator/iban_validator_response.rb', line 12 def initialize(raw_response) self.raw_response = raw_response end |
Instance Attribute Details
#raw_response ⇒ Object
Returns the value of attribute raw_response.
10 11 12 |
# File 'lib/iban_calculator/iban_validator_response.rb', line 10 def raw_response @raw_response end |
Instance Method Details
#account_number ⇒ Object
41 42 43 |
# 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 = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# 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 ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 ⇒ Object
24 25 26 |
# File 'lib/iban_calculator/iban_validator_response.rb', line 24 def bic_candidates @bic_candidates ||= BicCandidate.build_list(raw_response[:bic_candidates]) end |
#checks ⇒ Object
45 46 47 48 49 |
# 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 ⇒ Object
57 58 59 |
# File 'lib/iban_calculator/iban_validator_response.rb', line 57 def errors @errors ||= InvalidData.new('', return_code).errors end |
#return_code ⇒ Object
20 21 22 |
# File 'lib/iban_calculator/iban_validator_response.rb', line 20 def return_code @return_code ||= raw_response[:return_code].to_i end |
#updated_at ⇒ Object
51 52 53 54 55 |
# 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? ⇒ Boolean
16 17 18 |
# File 'lib/iban_calculator/iban_validator_response.rb', line 16 def valid? return_code < 128 end |