mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-28 22:23:33 +01:00
47 lines
1,007 B
Ruby
47 lines
1,007 B
Ruby
# encoding: utf-8
|
|
|
|
# Ruby wrapper module for calling ledger
|
|
module Ledger
|
|
module_function
|
|
|
|
@binary = 'ledger'
|
|
@file = '~/org/comptes.ledger'
|
|
|
|
def run( options, command = '', command_parameters = '' )
|
|
`#{@binary} -f #{@file} #{options} #{command} #{command_parameters}`
|
|
end
|
|
|
|
def version
|
|
run '--version'
|
|
end
|
|
|
|
def accounts( depth = 9999 )
|
|
run( '', 'accounts' )
|
|
.split( "\n" )
|
|
.map do |a|
|
|
a.split( ':' )
|
|
.each_slice( depth )
|
|
.to_a.first
|
|
end.uniq
|
|
end
|
|
|
|
def cleared
|
|
run '', 'cleared'
|
|
end
|
|
|
|
def monthly_register( category )
|
|
run( "--monthly --collapse --amount-data --exchange '€'", 'register', "#{category}" )
|
|
.split( "\n" )
|
|
.map do |line|
|
|
line_array = line.split
|
|
|
|
{ date: line_array[ 0 ],
|
|
amount: line_array[ 1 ].to_f }
|
|
end
|
|
end
|
|
|
|
def balance( period = nil )
|
|
period = period.nil? ? '' : "-p #{period}"
|
|
output run "--flat --exchange '€' #{period}", 'balance', "#{category}"
|
|
end
|
|
end
|