Class: LedgerGen::Transaction
- Inherits:
-
Object
- Object
- LedgerGen::Transaction
- Defined in:
- lib/ledger_gen/transaction.rb
Instance Method Summary collapse
- #cleared! ⇒ Object
- #comment(comment) ⇒ Object
- #date(date) ⇒ Object
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
- #payee(payee) ⇒ Object
- #posting(*args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
3 4 5 6 |
# File 'lib/ledger_gen/transaction.rb', line 3 def initialize @postings = [] @comments = [] end |
Instance Method Details
#cleared! ⇒ Object
16 17 18 |
# File 'lib/ledger_gen/transaction.rb', line 16 def cleared! @cleared = true end |
#comment(comment) ⇒ Object
34 35 36 |
# File 'lib/ledger_gen/transaction.rb', line 34 def comment(comment) @comments << comment end |
#date(date) ⇒ Object
8 9 10 |
# File 'lib/ledger_gen/transaction.rb', line 8 def date(date) @date = date end |
#payee(payee) ⇒ Object
12 13 14 |
# File 'lib/ledger_gen/transaction.rb', line 12 def payee(payee) @payee = payee end |
#posting(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ledger_gen/transaction.rb', line 20 def posting(*args) post = Posting.new @postings << post if args.length > 0 post.account args.shift if args.length > 0 post.amount args[0] end else yield post end end |
#to_s ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ledger_gen/transaction.rb', line 38 def to_s lines = ["#{date_string}#{cleared_string} #{@payee}"] @comments.each do |comment| lines << " ; #{comment}" end @postings.each do |post| lines << " " + post.to_s end lines.join("\n") end |