This commit is contained in:
Gwenhael Le Moine 2014-10-20 21:24:44 +02:00
parent 95fcd781a1
commit 7d5f893175

View file

@ -50,6 +50,20 @@ module Ledger
end
end
def balance( cleared = false, depth = nil, period = nil, categories = '' )
period = period.nil? ? '' : "-p '#{period}'"
depth = depth.nil? ? '' : "--depth #{depth}"
operation = cleared ? 'cleared' : 'balance'
run( "--flat --no-total --exchange '#{CURRENCY}' #{period} #{depth}", operation, categories )
.split( "\n" )
.map do |line|
line_array = line.split( "#{CURRENCY}" )
{ account: line_array[ 1 ].strip,
amount: line_array[ 0 ].tr( SEPARATOR, '.' ).to_f }
end
end
def cleared
run( "--flat --no-total --exchange '#{CURRENCY}'", 'cleared', 'Assets Equity' )
.split( "\n" )