Class: Kaui::Account

Inherits:
KillBillClient::Model::Account
  • Object
show all
Defined in:
app/models/kaui/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_id_or_key(account_id_or_key, with_balance = false, with_balance_and_cba = false, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/kaui/account.rb', line 3

def self.find_by_id_or_key(, with_balance = false, with_balance_and_cba = false, options = {})
  if  =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
    begin
      find_by_id(, with_balance, with_balance_and_cba, options)
    rescue => e
      begin
        # account_id_or_key looked like an id, but maybe it's an external key (this will happen in tests)?
        find_by_external_key(, with_balance, with_balance_and_cba, options)
      rescue => _
        # Nope - raise the initial exception
        raise e
      end
    end
  else
    find_by_external_key(, with_balance, with_balance_and_cba, options)
  end
end

.list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'app/models/kaui/account.rb', line 21

def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
  if search_key.present?
    find_in_batches_by_search_key(search_key, offset, limit, true, false, options)
  else
    find_in_batches(offset, limit, true, false, options)
  end
end

Instance Method Details

#balance_to_moneyObject



29
30
31
# File 'app/models/kaui/account.rb', line 29

def balance_to_money
  Kaui::Base.to_money(.abs, currency)
end

#cba_to_moneyObject



33
34
35
# File 'app/models/kaui/account.rb', line 33

def cba_to_money
  Kaui::Base.to_money(.abs, currency)
end

#persisted?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/kaui/account.rb', line 37

def persisted?
  !.blank?
end