diff --git a/Ledger/Ledger.hs b/Ledger/Ledger.hs index d1d97d508..65598a68c 100644 --- a/Ledger/Ledger.hs +++ b/Ledger/Ledger.hs @@ -5,7 +5,23 @@ names, a map from account names to 'Account's, and the display precision. -} -module Ledger.Ledger +module Ledger.Ledger ( +cacheLedger, +filterLedgerEntries, +filterLedgerTransactions, +accountnames, +ledgerAccount, +ledgerTransactions, +ledgerAccountTree, +addDataToAccountNameTree, +printentries, +printregister, +showLedgerAccounts, +showAccountTree, +isBoringInnerAccount, +isBoringInnerAccountName, +pruneBoringBranches, +) where import qualified Data.Map as Map import Data.Map ((!)) @@ -19,22 +35,6 @@ import Ledger.RawLedger import Ledger.Entry -rawLedgerTransactions :: RawLedger -> [Transaction] -rawLedgerTransactions = txns . entries - where - txns :: [Entry] -> [Transaction] - txns es = concat $ map flattenEntry $ zip es (iterate (+1) 1) - -rawLedgerAccountNamesUsed :: RawLedger -> [AccountName] -rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions - -rawLedgerAccountNames :: RawLedger -> [AccountName] -rawLedgerAccountNames = sort . expandAccountNames . rawLedgerAccountNamesUsed - -rawLedgerAccountNameTree :: RawLedger -> Tree AccountName -rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l - - instance Show Ledger where show l = printf "Ledger with %d entries, %d accounts" ((length $ entries $ rawledger l) + @@ -266,3 +266,21 @@ pruneBoringBranches = hasbalance = (/= 0) . abalance hastxns = (> 0) . length . atransactions +-- helpers + +rawLedgerTransactions :: RawLedger -> [Transaction] +rawLedgerTransactions = txns . entries + where + txns :: [Entry] -> [Transaction] + txns es = concat $ map flattenEntry $ zip es (iterate (+1) 1) + +rawLedgerAccountNamesUsed :: RawLedger -> [AccountName] +rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions + +rawLedgerAccountNames :: RawLedger -> [AccountName] +rawLedgerAccountNames = sort . expandAccountNames . rawLedgerAccountNamesUsed + +rawLedgerAccountNameTree :: RawLedger -> Tree AccountName +rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l + + diff --git a/Tests.hs b/Tests.hs index 9e95b1a51..9cc250b50 100644 --- a/Tests.hs +++ b/Tests.hs @@ -372,7 +372,7 @@ test_ledgerAccountNames = ["assets","assets:cash","assets:checking","assets:saving","equity","equity:opening balances", "expenses","expenses:food","expenses:food:dining","expenses:phone","expenses:vacation", "liabilities","liabilities:credit cards","liabilities:credit cards:discover"] - (rawLedgerAccountNames ledger7) + (accountnames l7) test_cacheLedger = assertEqual' 15 (length $ Map.keys $ accounts $ cacheLedger ledger7 nullpats)