minor cleanups.. time to go
This commit is contained in:
parent
8d91661e23
commit
e5834ffe2f
@ -70,10 +70,9 @@ cacheLedger l pats =
|
|||||||
in
|
in
|
||||||
Ledger l'' ant amap lprecision
|
Ledger l'' ant amap lprecision
|
||||||
|
|
||||||
-- | keep only entries whose description matches one of the
|
-- | keep only entries whose description matches one of the description
|
||||||
-- description patterns, if any, and which have at least one
|
-- patterns, and which have at least one transaction matching one of the
|
||||||
-- transaction matching one of the account patterns, if any.
|
-- account patterns. (One or both patterns may be the wildcard.)
|
||||||
-- No description or account patterns implies match all.
|
|
||||||
filterLedgerEntries :: (Regex,Regex) -> RawLedger -> RawLedger
|
filterLedgerEntries :: (Regex,Regex) -> RawLedger -> RawLedger
|
||||||
filterLedgerEntries (acctpat,descpat) (RawLedger ms ps es f) =
|
filterLedgerEntries (acctpat,descpat) (RawLedger ms ps es f) =
|
||||||
RawLedger ms ps filteredentries f
|
RawLedger ms ps filteredentries f
|
||||||
@ -89,9 +88,8 @@ filterLedgerEntries (acctpat,descpat) (RawLedger ms ps es f) =
|
|||||||
Nothing -> False
|
Nothing -> False
|
||||||
otherwise -> True
|
otherwise -> True
|
||||||
|
|
||||||
-- | in each ledger entry, filter out transactions which do not match
|
-- | in each ledger entry, filter out transactions which do not match the
|
||||||
-- the account patterns, if any. (Entries are no longer balanced
|
-- account patterns. (Entries are no longer balanced after this.)
|
||||||
-- after this.)
|
|
||||||
filterLedgerTransactions :: (Regex,Regex) -> RawLedger -> RawLedger
|
filterLedgerTransactions :: (Regex,Regex) -> RawLedger -> RawLedger
|
||||||
filterLedgerTransactions (acctpat,descpat) (RawLedger ms ps es f) =
|
filterLedgerTransactions (acctpat,descpat) (RawLedger ms ps es f) =
|
||||||
RawLedger ms ps (map filterentrytxns es) f
|
RawLedger ms ps (map filterentrytxns es) f
|
||||||
@ -219,6 +217,7 @@ showLedgerAccounts l maxdepth =
|
|||||||
concatMap
|
concatMap
|
||||||
(showAccountTree l)
|
(showAccountTree l)
|
||||||
(branches $ ledgerAccountTree l maxdepth)
|
(branches $ ledgerAccountTree l maxdepth)
|
||||||
|
-- XXX need to add up and show balances too
|
||||||
|
|
||||||
showAccountTree :: Ledger -> Tree Account -> String
|
showAccountTree :: Ledger -> Tree Account -> String
|
||||||
showAccountTree l = showAccountTree' l 0 . pruneBoringBranches
|
showAccountTree l = showAccountTree' l 0 . pruneBoringBranches
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
module Options (parseOptions, parsePatternArgs, wildcard, Flag(..), usage, ledgerFilePath)
|
module Options (parseOptions, parsePatternArgs, nullpats, wildcard, Flag(..), usage, ledgerFilePath)
|
||||||
where
|
where
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
import System.Directory
|
import System.Directory
|
||||||
@ -92,3 +92,4 @@ regexFor ss = mkRegex $ "(" ++ (unwords $ intersperse "|" ss) ++ ")"
|
|||||||
wildcard :: Regex
|
wildcard :: Regex
|
||||||
wildcard = mkRegex ".*"
|
wildcard = mkRegex ".*"
|
||||||
|
|
||||||
|
nullpats = (wildcard,wildcard)
|
||||||
|
|||||||
4
Tests.hs
4
Tests.hs
@ -284,7 +284,7 @@ ledger7 = RawLedger
|
|||||||
]
|
]
|
||||||
""
|
""
|
||||||
|
|
||||||
l7 = cacheLedger ledger7 (wildcard,wildcard)
|
l7 = cacheLedger ledger7 nullpats
|
||||||
|
|
||||||
timelogentry1_str = "i 2007/03/11 16:19:00 hledger\n"
|
timelogentry1_str = "i 2007/03/11 16:19:00 hledger\n"
|
||||||
timelogentry1 = TimeLogEntry 'i' "2007/03/11 16:19:00" "hledger"
|
timelogentry1 = TimeLogEntry 'i' "2007/03/11 16:19:00" "hledger"
|
||||||
@ -375,7 +375,7 @@ test_ledgerAccountNames =
|
|||||||
(rawLedgerAccountNames ledger7)
|
(rawLedgerAccountNames ledger7)
|
||||||
|
|
||||||
test_cacheLedger =
|
test_cacheLedger =
|
||||||
assertEqual' 15 (length $ Map.keys $ accounts $ cacheLedger ledger7 (wildcard,wildcard))
|
assertEqual' 15 (length $ Map.keys $ accounts $ cacheLedger ledger7 nullpats)
|
||||||
|
|
||||||
test_showLedgerAccounts =
|
test_showLedgerAccounts =
|
||||||
assertEqual' 4 (length $ lines $ showLedgerAccounts l7 1)
|
assertEqual' 4 (length $ lines $ showLedgerAccounts l7 1)
|
||||||
|
|||||||
@ -77,9 +77,9 @@ balance opts pats = parseLedgerAndDo opts pats printbalance
|
|||||||
where
|
where
|
||||||
showsubs = (ShowSubs `elem` opts)
|
showsubs = (ShowSubs `elem` opts)
|
||||||
depth = case (pats, showsubs) of
|
depth = case (pats, showsubs) of
|
||||||
-- when there are no account patterns and no -s, show
|
-- when there are no filter patterns and no -s, show
|
||||||
-- only to depth 1. (This was clearer when we used maybe.)
|
-- only to depth 1. (This was clearer when we used maybe.)
|
||||||
((wildcard,_), False) -> 1
|
(nullpats, False) -> 1
|
||||||
otherwise -> 9999
|
otherwise -> 9999
|
||||||
|
|
||||||
-- | parse the user's specified ledger file and do some action with it
|
-- | parse the user's specified ledger file and do some action with it
|
||||||
@ -104,7 +104,7 @@ rawledger = do
|
|||||||
ledger :: IO Ledger
|
ledger :: IO Ledger
|
||||||
ledger = do
|
ledger = do
|
||||||
l <- rawledger
|
l <- rawledger
|
||||||
return $ cacheLedger l (wildcard,wildcard)
|
return $ cacheLedger l nullpats
|
||||||
|
|
||||||
-- | get a Ledger from the given file path
|
-- | get a Ledger from the given file path
|
||||||
rawledgerfromfile :: String -> IO RawLedger
|
rawledgerfromfile :: String -> IO RawLedger
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user