mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2025-02-05 20:46:02 +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
|
end
|
||||||
|
|
||||||
get '/api/ledger/balance/?' do
|
get '/api/ledger/balance/?' do
|
||||||
Ledger.balance # .to_json
|
Ledger.balance.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/ledger/balance/depth/:depth/?' do
|
get '/api/ledger/balance/depth/:depth/?' do
|
||||||
param :depth, Integer, required: true
|
param :depth, Integer, required: true
|
||||||
|
|
||||||
Ledger.balance( false, params[ :depth ] ) # .to_json
|
Ledger.balance( false, params[ :depth ] ).to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/ledger/cleared/?' do
|
# get '/api/ledger/cleared/?' do
|
||||||
Ledger.balance( true ) # .to_json
|
# Ledger.balance( true ).to_json
|
||||||
end
|
# end
|
||||||
|
|
||||||
get '/api/ledger/cleared/depth/:depth/?' do
|
# get '/api/ledger/cleared/depth/:depth/?' do
|
||||||
param :depth, Integer, required: true
|
# param :depth, Integer, required: true
|
||||||
|
|
||||||
Ledger.balance( true, params[ :depth ] ) # .to_json
|
# Ledger.balance( true, params[ :depth ] ).to_json
|
||||||
end
|
# end
|
||||||
|
|
||||||
get '/api/ledger/version/?' do
|
get '/api/ledger/version/?' do
|
||||||
Ledger.version
|
Ledger.version
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
ENV[ 'RACK_ENV' ] = 'development'
|
ENV[ 'RACK_ENV' ] = 'development'
|
||||||
|
|
||||||
|
CURRENCY = '€'
|
||||||
|
SEPARATOR = ','
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Ledger
|
||||||
end
|
end
|
||||||
|
|
||||||
def register( category, options='' )
|
def register( category, options='' )
|
||||||
run( "#{options} --collapse --amount-data --exchange '€'", 'register', "#{category}" )
|
run( "#{options} --collapse --amount-data --exchange '#{CURRENCY}'", 'register', "#{category}" )
|
||||||
.split( "\n" )
|
.split( "\n" )
|
||||||
.map do |line|
|
.map do |line|
|
||||||
line_array = line.split
|
line_array = line.split
|
||||||
|
@ -48,6 +48,13 @@ module Ledger
|
||||||
period = period.nil? ? '' : "-p #{period}"
|
period = period.nil? ? '' : "-p #{period}"
|
||||||
depth = depth.nil? ? '' : "--depth #{depth}"
|
depth = depth.nil? ? '' : "--depth #{depth}"
|
||||||
operation = cleared ? 'cleared' : 'balance'
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue