Class: Egg::Transaction
- Inherits:
-
Object
- Object
- Egg::Transaction
- Defined in:
- lib/egg/transaction.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
Instance Method Summary collapse
-
#initialize(date, description, money) ⇒ Transaction
constructor
A new instance of Transaction.
- #note ⇒ Object
- #ofx_id ⇒ Object
- #payee ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
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
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
12 13 14 |
# File 'lib/egg/transaction.rb', line 12 def amount @amount end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
12 13 14 |
# File 'lib/egg/transaction.rb', line 12 def date @date end |
Instance Method Details
#note ⇒ Object
16 17 18 |
# File 'lib/egg/transaction.rb', line 16 def note @description.note end |
#ofx_id ⇒ Object
19 20 21 |
# File 'lib/egg/transaction.rb', line 19 def ofx_id @ofx_id ||= Digest::MD5.hexdigest(to_s) end |
#payee ⇒ Object
13 14 15 |
# File 'lib/egg/transaction.rb', line 13 def payee @description.payee end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/egg/transaction.rb', line 22 def to_s [date, @raw_description, amount].join(', ') end |
#type ⇒ Object
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 |