Class: Egg::Transaction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, description, money) ⇒ Transaction

Returns a new instance of Transaction.



5
6
7
8
9
10
11
# File 'lib/egg/transaction.rb', line 5

def initialize(date, description, money)
  @date = Date.build(date)
  @raw_description = description
  @description = Description.new(description)
  @amount = Money.new(money).to_f
  @ofx_id = nil
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



12
13
14
# File 'lib/egg/transaction.rb', line 12

def amount
  @amount
end

#dateObject (readonly)

Returns the value of attribute date.



12
13
14
# File 'lib/egg/transaction.rb', line 12

def date
  @date
end

Instance Method Details

#noteObject



16
17
18
# File 'lib/egg/transaction.rb', line 16

def note
  @description.note
end

#ofx_idObject



19
20
21
# File 'lib/egg/transaction.rb', line 19

def ofx_id
  @ofx_id ||= Digest::MD5.hexdigest(to_s)
end

#payeeObject



13
14
15
# File 'lib/egg/transaction.rb', line 13

def payee
  @description.payee
end

#to_sObject



22
23
24
# File 'lib/egg/transaction.rb', line 22

def to_s
  [date, @raw_description, amount].join(', ')
end

#typeObject



25
26
27
28
29
30
31
# File 'lib/egg/transaction.rb', line 25

def type
  if payee =~ /INTEREST/
    'INT'
  else
    (amount < 0) ? 'DEBIT' : 'CREDIT'
  end
end