Class: XeroGateway::AccountsList
- Inherits:
-
Object
- Object
- XeroGateway::AccountsList
- Defined in:
- lib/xero_gateway/accounts_list.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
All accessible fields.
-
#accounts_by_code ⇒ Object
readonly
Hash of accounts with the account code as the key.
-
#gateway ⇒ Object
Xero::Gateway associated with this invoice.
-
#loaded ⇒ Object
readonly
Boolean representing whether the accounts list has been loaded.
Instance Method Summary collapse
-
#[](account_code) ⇒ Object
Alias [] method to find_by_code.
-
#find_all_by_tax_type(tax_type) ⇒ Object
Return a list of all accounts matching tax_type.
-
#find_all_by_type(account_type) ⇒ Object
Return a list of all accounts matching account_type.
-
#find_by_code(account_code) ⇒ Object
Lookup account by account_code.
-
#initialize(gateway, initial_load = true) ⇒ AccountsList
constructor
A new instance of AccountsList.
- #load ⇒ Object
- #loaded? ⇒ Boolean
Constructor Details
#initialize(gateway, initial_load = true) ⇒ AccountsList
Returns a new instance of AccountsList.
18 19 20 21 22 23 24 |
# File 'lib/xero_gateway/accounts_list.rb', line 18 def initialize(gateway, initial_load = true) raise NoGatewayError unless gateway && gateway.is_a?(XeroGateway::Gateway) @gateway = gateway @loaded = false load if initial_load end |
Instance Attribute Details
#accounts ⇒ Object
All accessible fields
8 9 10 |
# File 'lib/xero_gateway/accounts_list.rb', line 8 def accounts @accounts end |
#accounts_by_code ⇒ Object (readonly)
Hash of accounts with the account code as the key.
11 12 13 |
# File 'lib/xero_gateway/accounts_list.rb', line 11 def accounts_by_code @accounts_by_code end |
#gateway ⇒ Object
Xero::Gateway associated with this invoice.
5 6 7 |
# File 'lib/xero_gateway/accounts_list.rb', line 5 def gateway @gateway end |
#loaded ⇒ Object (readonly)
Boolean representing whether the accounts list has been loaded.
14 15 16 |
# File 'lib/xero_gateway/accounts_list.rb', line 14 def loaded @loaded end |
Instance Method Details
#[](account_code) ⇒ Object
Alias [] method to find_by_code.
50 51 52 |
# File 'lib/xero_gateway/accounts_list.rb', line 50 def [](account_code) find_by_code(account_code) end |
#find_all_by_tax_type(tax_type) ⇒ Object
Return a list of all accounts matching tax_type.
64 65 66 67 68 69 70 |
# File 'lib/xero_gateway/accounts_list.rb', line 64 def find_all_by_tax_type(tax_type) raise AccountsListNotLoadedError unless loaded? @accounts.inject([]) do | list, account | list << account if account.tax_type == tax_type list end end |
#find_all_by_type(account_type) ⇒ Object
Return a list of all accounts matching account_type.
55 56 57 58 59 60 61 |
# File 'lib/xero_gateway/accounts_list.rb', line 55 def find_all_by_type(account_type) raise AccountsListNotLoadedError unless loaded? @accounts.inject([]) do | list, account | list << account if account.type == account_type list end end |
#find_by_code(account_code) ⇒ Object
Lookup account by account_code.
44 45 46 47 |
# File 'lib/xero_gateway/accounts_list.rb', line 44 def find_by_code(account_code) raise AccountsListNotLoadedError unless loaded? @accounts_by_code[account_code.to_s] end |
#load ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/xero_gateway/accounts_list.rb', line 26 def load @loaded = false response = gateway.get_accounts @accounts = response.accounts @loaded = true # Cache accounts by code. @accounts_by_code = {} @accounts.each do | account | @accounts_by_code[account.code.to_s] = account end end |
#loaded? ⇒ Boolean
39 40 41 |
# File 'lib/xero_gateway/accounts_list.rb', line 39 def loaded? @loaded == true end |