From 14dedcf7795f5a90a1b80c00cb20e36fadd80d92 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 3 Sep 2015 16:55:41 +0200 Subject: [PATCH] add top level accounts --- lib/ledger.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ledger.rb b/lib/ledger.rb index 33d39eae..e61557d9 100644 --- a/lib/ledger.rb +++ b/lib/ledger.rb @@ -19,13 +19,17 @@ module Ledger end def accounts( depth = 9999 ) - run( '', 'accounts' ) - .split( "\n" ) - .map do |a| + accounts = run( '', 'accounts' ) + .split( "\n" ) + .map do |a| a.split( ':' ) - .each_slice( depth ) - .to_a.first + .each_slice( depth ) + .to_a.first end.uniq + + top_level_accounts = accounts.map(&:first).uniq.map { |account| [ account ] } + + ( accounts + top_level_accounts ).sort end def dates_salaries( category = 'salaire' )