Class: AspireBudget::Models::CategoryTransfer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date:, amount:, from:, to:, memo:) ⇒ CategoryTransfer

Returns a new instance of CategoryTransfer.



20
21
22
23
24
25
26
# File 'lib/aspire_budget/models/category_transfer.rb', line 20

def initialize(date:, amount:, from:, to:, memo:)
  @date = date.nil? ? Date.today : Utils.parse_date(date)
  @amount = amount.to_f
  @from = from || 'Available to Budget'
  @to = to
  @memo = memo
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



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

def amount
  @amount
end

#dateObject (readonly)

Returns the value of attribute date.



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

def date
  @date
end

#fromObject (readonly)

Returns the value of attribute from.



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

def from
  @from
end

#memoObject (readonly)

Returns the value of attribute memo.



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

def memo
  @memo
end

#toObject (readonly)

Returns the value of attribute to.



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

def to
  @to
end

Class Method Details

.from_row(header, row) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/aspire_budget/models/category_transfer.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])
  end

  new(**params)
end

Instance Method Details

#to_row(header) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/aspire_budget/models/category_transfer.rb', line 28

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

    value
  end
end