Class: Rledger::Statement
- Inherits:
-
Object
- Object
- Rledger::Statement
- Defined in:
- lib/rledger/report/statement.rb
Instance Method Summary collapse
- #compute(voice) ⇒ Object
-
#initialize(transactions) ⇒ Statement
constructor
A new instance of Statement.
- #to_s ⇒ Object
Constructor Details
#initialize(transactions) ⇒ Statement
Returns a new instance of Statement.
3 4 5 |
# File 'lib/rledger/report/statement.rb', line 3 def initialize(transactions) @transactions = transactions end |
Instance Method Details
#compute(voice) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rledger/report/statement.rb', line 7 def compute voice @statement = [] cumulative = Amount.new @transactions.each do |transaction| if transaction.contains? voice # the cumulative is computed by adding all posts with voice # # this is to ensure cumulative is in the same currency of # voice (if we used the currency in the posts not containing # voice to compute the cumulative, we would risk using # different currencies, if the voice appears in multi # currency transactions transaction.posts_with(voice).each do |post| cumulative.add!(post.amount) end # This is to generate a new amount per line # (if we used cumulative instead, the array will # insert a reference to the object and since add! has a side effect, # we would build N-references to the same object, which has the last # value assigned line_total = Amount.new line_total.add!(cumulative) complement = transaction.posts_without(voice) statement_line = { :date => transaction.date, :id => transaction.id, :payee => transaction.payee, :voice => complement.size > 1 ? "-- split --" : complement[0].voice, :amount => complement[0].amount, :cumulative => line_total } @statement << statement_line # transaction.posts_without(voice).each do |post| # # This is to generate a new amount per line # # (if we used cumulative instead, the array will # # insert a reference to the object and since add! has a side effect, # # we would build N-references to the same object, which has the last # # value assigned # line_total = Amount.new # line_total.add!(cumulative) # # statement_line = { :date => transaction.date, # :id => transaction.id, # :payee => transaction.payee, # :voice => post.voice, # :amount => post.amount, # :cumulative => line_total } # @statement << statement_line # end end end end |
#to_s ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/rledger/report/statement.rb', line 65 def to_s @statement.each do |line| printf "%10s %5.5s %-30.30s %-30.30s %10s %10s\n", line[:date], line[:id], line[:payee], line[:voice], line[:amount], line[:cumulative] end "" end |