Class: Ynaby::Budget

Inherits:
Base
  • Object
show all
Defined in:
lib/ynaby/budget.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#ynab_client

Constructor Details

#initialize(id:, name:, last_modified_on:, date_format:, currency_format:, user:) ⇒ Budget

Returns a new instance of Budget.



5
6
7
8
9
10
11
12
# File 'lib/ynaby/budget.rb', line 5

def initialize(id:, name:, last_modified_on:, date_format:, currency_format:, user:)
  @id = id
  @name = name
  @last_modified_on = last_modified_on
  @date_format = date_format
  @currency_format = currency_format || {}
  @user = user
end

Instance Attribute Details

#currency_formatObject (readonly)

Returns the value of attribute currency_format.



3
4
5
# File 'lib/ynaby/budget.rb', line 3

def currency_format
  @currency_format
end

#date_formatObject (readonly)

Returns the value of attribute date_format.



3
4
5
# File 'lib/ynaby/budget.rb', line 3

def date_format
  @date_format
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/ynaby/budget.rb', line 3

def id
  @id
end

#last_modified_onObject (readonly)

Returns the value of attribute last_modified_on.



3
4
5
# File 'lib/ynaby/budget.rb', line 3

def last_modified_on
  @last_modified_on
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/ynaby/budget.rb', line 3

def name
  @name
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/ynaby/budget.rb', line 3

def user
  @user
end

Class Method Details

.parse(object, user) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/ynaby/budget.rb', line 30

def self.parse(object, user)
  new(
    id: object.id,
    name: object.name,
    last_modified_on: object.last_modified_on,
    date_format: object.date_format.to_hash,
    currency_format: object.currency_format.to_hash,
    user: user
  )
end

Instance Method Details

#account(account_id) ⇒ Object



21
22
23
24
# File 'lib/ynaby/budget.rb', line 21

def ()
  response = ynab_client.accounts.(id, )
  Account.parse(object: response.data., budget: self)
end

#accountsObject



14
15
16
17
18
19
# File 'lib/ynaby/budget.rb', line 14

def accounts
  response = ynab_client.accounts.get_accounts(@id)
  response.data.accounts.map do ||
    Account.parse(object: , budget: self)
  end
end

#api_tokenObject



41
42
43
# File 'lib/ynaby/budget.rb', line 41

def api_token
  user.api_token
end

#currency_codeObject



26
27
28
# File 'lib/ynaby/budget.rb', line 26

def currency_code
  currency_format[:iso_code]
end