Class: AspireBudget::Models::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/aspire_budget/models/transaction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date:, outflow:, inflow:, category:, account:, memo:, status:) ⇒ Transaction

rubocop:disable Metrics/ParameterLists



22
23
24
25
26
27
28
29
30
# File 'lib/aspire_budget/models/transaction.rb', line 22

def initialize(date:, outflow:, inflow:, category:, account:, memo:, status:)
  @date = date.nil? ? Date.today : Utils.parse_date(date)
  @outflow = outflow.to_f
  @inflow = inflow.to_f
  @category = category
  @account = 
  @memo = memo
  @status = status
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



8
9
10
# File 'lib/aspire_budget/models/transaction.rb', line 8

def 
  @account
end

#categoryObject (readonly)

Returns the value of attribute category.



8
9
10
# File 'lib/aspire_budget/models/transaction.rb', line 8

def category
  @category
end

#dateObject (readonly)

Returns the value of attribute date.



8
9
10
# File 'lib/aspire_budget/models/transaction.rb', line 8

def date
  @date
end

#inflowObject (readonly)

Returns the value of attribute inflow.



8
9
10
# File 'lib/aspire_budget/models/transaction.rb', line 8

def inflow
  @inflow
end

#memoObject (readonly)

Returns the value of attribute memo.



8
9
10
# File 'lib/aspire_budget/models/transaction.rb', line 8

def memo
  @memo
end

#outflowObject (readonly)

Returns the value of attribute outflow.



8
9
10
# File 'lib/aspire_budget/models/transaction.rb', line 8

def outflow
  @outflow
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/aspire_budget/models/transaction.rb', line 8

def status
  @status
end

Class Method Details

.from_row(header, row) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/aspire_budget/models/transaction.rb', line 10

def self.from_row(header, row)
  params = header.zip(row).to_h

  params.tap do |h|
    h[:date] = Utils.parse_date(h[:date])
    h[:status] = Utils.parse_status(h[:status])
  end

  new(**params)
end

Instance Method Details

#to_row(header) ⇒ Object

rubocop:enable Metrics/ParameterLists



33
34
35
36
37
38
39
40
41
# File 'lib/aspire_budget/models/transaction.rb', line 33

def to_row(header)
  header.map do |h|
    value = send(h)
    next Utils.serialize_date(value) if h == :date
    next Utils.serialize_status(value) if h == :status

    value
  end
end