mirror of
https://github.com/gwenhael-le-moine/credger.git
synced 2024-12-26 09:58:36 +01:00
capitalize on ENV
This commit is contained in:
parent
18fa287693
commit
f7e5e655ac
2 changed files with 8 additions and 9 deletions
|
@ -2,8 +2,8 @@ require "kemal"
|
||||||
|
|
||||||
require "./ledger"
|
require "./ledger"
|
||||||
|
|
||||||
CURRENCY = "€"
|
ENV["CREDGER_CURRENCY"] ||= "€"
|
||||||
SEPARATOR = ","
|
ENV["CREDGER_SEPARATOR"] ||= ","
|
||||||
|
|
||||||
ENV["PORT"] ||= "3000"
|
ENV["PORT"] ||= "3000"
|
||||||
|
|
||||||
|
|
13
ledger.cr
13
ledger.cr
|
@ -1,11 +1,10 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
require "csv"
|
require "csv"
|
||||||
|
|
||||||
# Crystal wrapper module for calling ledger
|
# Crystal wrapper module for calling ledger
|
||||||
class Ledger
|
class Ledger
|
||||||
def initialize( binary : String = "ledger",
|
def initialize( binary : String = "ledger",
|
||||||
ledger_file : String = ENV[ "LEDGER_FILE" ] ||= "/home/cycojesus/org/comptes.ledger" )
|
ledger_file : String = ENV[ "LEDGER_FILE" ] ||= "${ENV[ \"HOME\" ]}/org/comptes.ledger" )
|
||||||
@binary = binary
|
@binary = binary
|
||||||
@file = ledger_file
|
@file = ledger_file
|
||||||
end
|
end
|
||||||
|
@ -47,14 +46,14 @@ class Ledger
|
||||||
depth = depth.nil? ? "" : "--depth #{depth}"
|
depth = depth.nil? ? "" : "--depth #{depth}"
|
||||||
operation = cleared ? "cleared" : "balance"
|
operation = cleared ? "cleared" : "balance"
|
||||||
|
|
||||||
run( "--flat --no-total --exchange '#{CURRENCY}' #{period} #{depth}", operation, categories )
|
run( "--flat --no-total --exchange '#{ENV["CREDGER_CURRENCY"]}' #{period} #{depth}", operation, categories )
|
||||||
.split( "\n" )
|
.split( "\n" )
|
||||||
.reject {|line| line.empty?}
|
.reject {|line| line.empty?}
|
||||||
.map do |line|
|
.map do |line|
|
||||||
line_array = line.split( "#{CURRENCY}" )
|
line_array = line.split( ENV["CREDGER_CURRENCY"] )
|
||||||
|
|
||||||
{ account: line_array[ 1 ].strip,
|
{ account: line_array[ 1 ].strip,
|
||||||
amount: line_array[ 0 ].tr( SEPARATOR, "." ).to_f }
|
amount: line_array[ 0 ].tr( ENV["CREDGER_SEPARATOR"], "." ).to_f }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ class Ledger
|
||||||
result = {} of String => Array(NamedTuple(date: String, amount: String, currency: String))
|
result = {} of String => Array(NamedTuple(date: String, amount: String, currency: String))
|
||||||
categories.map do |category|
|
categories.map do |category|
|
||||||
result[category] = CSV
|
result[category] = CSV
|
||||||
.parse( run( "-MAn --exchange '#{CURRENCY}' #{period} #{granularity}", "csv --no-revalued", category ) )
|
.parse( run( "-MAn --exchange '#{ENV["CREDGER_CURRENCY"]}' #{period} #{granularity}", "csv --no-revalued", category ) )
|
||||||
.map do |row|
|
.map do |row|
|
||||||
{ date: row[ 0 ],
|
{ date: row[ 0 ],
|
||||||
amount: row[ 5 ],
|
amount: row[ 5 ],
|
||||||
|
@ -82,7 +81,7 @@ class Ledger
|
||||||
period = period == "" ? "" : "-p '#{period}'"
|
period = period == "" ? "" : "-p '#{period}'"
|
||||||
|
|
||||||
CSV
|
CSV
|
||||||
.parse( run( "--exchange '#{CURRENCY}' #{period}", "csv --no-revalued", categories.join(" ") ) )
|
.parse( run( "--exchange '#{ENV["CREDGER_CURRENCY"]}' #{period}", "csv --no-revalued", categories.join(" ") ) )
|
||||||
.map do |row|
|
.map do |row|
|
||||||
{ date: row[ 0 ],
|
{ date: row[ 0 ],
|
||||||
payee: row[ 2 ],
|
payee: row[ 2 ],
|
||||||
|
|
Loading…
Reference in a new issue