Class: Rledger::Balance
- Inherits:
-
Object
- Object
- Rledger::Balance
- Defined in:
- lib/rledger/report/balance.rb
Overview
Balance computes the balance of leaves (at the moment)
Instance Method Summary collapse
- #compute ⇒ Object
-
#initialize(transactions) ⇒ Balance
constructor
A new instance of Balance.
- #to_s ⇒ Object
Constructor Details
#initialize(transactions) ⇒ Balance
Returns a new instance of Balance.
4 5 6 |
# File 'lib/rledger/report/balance.rb', line 4 def initialize(transactions) @transactions = transactions end |
Instance Method Details
#compute ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rledger/report/balance.rb', line 8 def compute @balance = Hash.new @transactions.each do |t| t.posts.each do |p| elements = disaggregate p.voice elements.each do |element| @balance[element] ? @balance[element].add!(p.amount) : @balance[element] = p.amount end end end end |
#to_s ⇒ Object
22 23 24 25 |
# File 'lib/rledger/report/balance.rb', line 22 def to_s @balance.keys.sort.map { |k| puts "#{k} #{@balance[k]}" } "" end |