mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2025-01-14 08:01:07 +01:00
JSONify balance output, disable cleared for the moment
This commit is contained in:
parent
09678bd48e
commit
84e9350676
3 changed files with 21 additions and 11 deletions
18
app.rb
18
app.rb
|
@ -42,24 +42,24 @@ class LedgerRbApp < Sinatra::Base
|
|||
end
|
||||
|
||||
get '/api/ledger/balance/?' do
|
||||
Ledger.balance # .to_json
|
||||
Ledger.balance.to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/balance/depth/:depth/?' do
|
||||
param :depth, Integer, required: true
|
||||
|
||||
Ledger.balance( false, params[ :depth ] ) # .to_json
|
||||
Ledger.balance( false, params[ :depth ] ).to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/cleared/?' do
|
||||
Ledger.balance( true ) # .to_json
|
||||
end
|
||||
# get '/api/ledger/cleared/?' do
|
||||
# Ledger.balance( true ).to_json
|
||||
# end
|
||||
|
||||
get '/api/ledger/cleared/depth/:depth/?' do
|
||||
param :depth, Integer, required: true
|
||||
# get '/api/ledger/cleared/depth/:depth/?' do
|
||||
# param :depth, Integer, required: true
|
||||
|
||||
Ledger.balance( true, params[ :depth ] ) # .to_json
|
||||
end
|
||||
# Ledger.balance( true, params[ :depth ] ).to_json
|
||||
# end
|
||||
|
||||
get '/api/ledger/version/?' do
|
||||
Ledger.version
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# encoding: utf-8
|
||||
|
||||
ENV[ 'RACK_ENV' ] = 'development'
|
||||
|
||||
CURRENCY = '€'
|
||||
SEPARATOR = ','
|
||||
|
|
|
@ -26,7 +26,7 @@ module Ledger
|
|||
end
|
||||
|
||||
def register( category, options='' )
|
||||
run( "#{options} --collapse --amount-data --exchange '€'", 'register', "#{category}" )
|
||||
run( "#{options} --collapse --amount-data --exchange '#{CURRENCY}'", 'register', "#{category}" )
|
||||
.split( "\n" )
|
||||
.map do |line|
|
||||
line_array = line.split
|
||||
|
@ -48,6 +48,13 @@ module Ledger
|
|||
period = period.nil? ? '' : "-p #{period}"
|
||||
depth = depth.nil? ? '' : "--depth #{depth}"
|
||||
operation = cleared ? 'cleared' : 'balance'
|
||||
run "--flat --exchange '€' #{period} #{depth}", operation
|
||||
run( "--flat --no-total --exchange '#{CURRENCY}' #{period} #{depth}", operation )
|
||||
.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
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue