Class: Kaui::Account

Inherits:
Base
  • Object
show all
Defined in:
app/models/kaui/account.rb

Instance Attribute Summary

Attributes inherited from Base

#errors

Instance Method Summary collapse

Methods inherited from Base

#==, all, #attributes=, camelize, convert_hash_keys, count, define_attr, #destroy, find, from_json, has_many, has_one, human_attribute_name, lookup_ancestors, #new_record?, #persisted?, #read_attribute_for_validation, #save, #to_hash, to_money, #update_attributes

Constructor Details

#initialize(data = {}) ⇒ Account

Returns a new instance of Account.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/kaui/account.rb', line 21

def initialize(data = {})
  super(:account_id => data['accountId'],
        :external_key => data['externalKey'],
        :name => data['name'] || "#{data['firstName'] || ''}#{data.has_key?('firstName') ? ' ' : ''}#{data['lastName'] || ''}",
        :first_name_length => data['length'] || (data.has_key?('firstName') ? data['firstName'].length : 0),
        :email => data['email'],
        :currency => data['currency'],
        :payment_method_id => data['paymentMethodId'],
        :timezone => data['timeZone'] || data['time_zone'] || data['timezone'],
        :address1 => data['address1'],
        :address2 => data['address2'],
        :company =>  data['company'],
        :state => data['state'],
        :country => data['country'],
        :phone => data['phone'],
        :bill_cycle_day => data['billCycleDay'],
        :balance => data['accountBalance'],
        :cba => data['accountCBA'],
        :is_notified_for_invoices => data['isNotifiedForInvoices'])
end

Instance Method Details

#balance_to_moneyObject



46
47
48
# File 'app/models/kaui/account.rb', line 46

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

#cba_to_moneyObject



50
51
52
# File 'app/models/kaui/account.rb', line 50

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

#to_paramObject



42
43
44
# File 'app/models/kaui/account.rb', line 42

def to_param
  @account_id
end