rename metadata fields to tags

This commit is contained in:
Simon Michael 2012-05-27 22:59:06 +00:00
parent 3ee6a351f3
commit 2fb2aea056
9 changed files with 81 additions and 82 deletions

View File

@ -516,7 +516,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -525,7 +525,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -534,7 +534,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars (-1)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -543,7 +543,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars (-1)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [nullamt]))
@ -554,7 +554,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [dollars 1]))
@ -565,7 +565,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars (-2)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [dollars (-2)]))
@ -577,7 +577,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [dollars 1]))
@ -588,7 +588,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [dollars 1]))
@ -600,7 +600,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars (-1)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [dollars (-1)]))
@ -611,7 +611,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars (-1)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [dollars (-1)]))
@ -623,7 +623,7 @@ tests_journalAccountInfo = [
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
] (Mixed [dollars 1]))
@ -712,7 +712,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
tcode="",
tdescription="income",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -720,7 +720,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -729,7 +729,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(missingmixedamt),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -743,7 +743,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
tcode="",
tdescription="gift",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -751,7 +751,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -760,7 +760,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(missingmixedamt),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -774,7 +774,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
tcode="",
tdescription="save",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -782,7 +782,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -791,7 +791,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars (-1)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -805,7 +805,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
tcode="",
tdescription="eat & shop",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -813,7 +813,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -822,7 +822,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -831,7 +831,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(missingmixedamt),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -845,7 +845,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
tcode="",
tdescription="pay off",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -853,7 +853,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -862,7 +862,7 @@ Right samplejournal = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars (-1)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],

View File

@ -35,8 +35,8 @@ module Hledger.Data.Posting (
showPosting,
showPostingForRegister,
-- * misc.
postingMetadataAsLines,
metadataAsLines,
postingTagsAsLines,
tagsAsLines,
showComment,
tests_Hledger_Data_Posting
)
@ -62,7 +62,7 @@ nullposting = Posting False "" nullmixedamt "" RegularPosting [] Nothing
showPosting :: Posting -> String
showPosting p@Posting{paccount=a,pamount=amt,ptype=t} =
unlines $ [concatTopPadded [showaccountname a ++ " ", showamount amt, showComment (pcomment p)]] ++ postingMetadataAsLines p
unlines $ [concatTopPadded [showaccountname a ++ " ", showamount amt, showComment (pcomment p)]] ++ postingTagsAsLines p
where
ledger3ishlayout = False
acctnamewidth = if ledger3ishlayout then 25 else 22
@ -74,11 +74,11 @@ showPosting p@Posting{paccount=a,pamount=amt,ptype=t} =
showamount = padleft 12 . showMixedAmount
postingMetadataAsLines :: Posting -> [String]
postingMetadataAsLines = metadataAsLines . pmetadata
postingTagsAsLines :: Posting -> [String]
postingTagsAsLines = tagsAsLines . ptags
metadataAsLines :: [(String, String)] -> [String]
metadataAsLines mds = map (\(k,v) -> " ; " ++ k++": "++v) mds
tagsAsLines :: [(String, String)] -> [String]
tagsAsLines mds = map (\(k,v) -> " ; " ++ k++": "++v) mds
showComment :: String -> String
showComment s = if null s then "" else " ; " ++ s

View File

@ -81,7 +81,7 @@ entryFromTimeLogInOut i o
tcode = "",
tdescription = showtime itod ++ "-" ++ showtime otod,
tcomment = "",
tmetadata = [],
ttags = [],
tpostings = ps,
tpreceding_comment_lines=""
}
@ -95,7 +95,7 @@ entryFromTimeLogInOut i o
hrs = elapsedSeconds (toutc otime) (toutc itime) / 3600 where toutc = localTimeToUTC utc
amount = Mixed [hours hrs]
ps = [Posting{pstatus=False,paccount=acctname,pamount=amount,
pcomment="",ptype=VirtualPosting,pmetadata=[],ptransaction=Just t}]
pcomment="",ptype=VirtualPosting,ptags=[],ptransaction=Just t}]
tests_Hledger_Data_TimeLog = TestList [

View File

@ -2,8 +2,8 @@
A 'Transaction' represents a movement of some commodity(ies) between two
or more accounts. It consists of multiple account 'Posting's which balance
to zero, a date, and optional metadata like description and cleared
status.
to zero, a date, and optional extras like description, cleared status, and
tags.
-}
@ -65,7 +65,7 @@ nulltransaction = Transaction {
tcode="",
tdescription="",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[],
tpreceding_comment_lines=""
}
@ -103,7 +103,7 @@ tests_showTransactionUnelided = [
tcode="code",
tdescription="desc",
tcomment="tcomment1\ntcomment2\n",
tmetadata=[("ttag1","val1")],
ttags=[("ttag1","val1")],
tpostings=[
nullposting{
pstatus=True,
@ -111,7 +111,7 @@ tests_showTransactionUnelided = [
pamount=Mixed [dollars 1, hours 2],
pcomment="pcomment1\npcomment2\n",
ptype=RegularPosting,
pmetadata=[("ptag1","val1"),("ptag2","val2")]
ptags=[("ptag1","val1"),("ptag2","val2")]
}
]
}
@ -133,7 +133,7 @@ showTransaction' :: Bool -> Transaction -> String
showTransaction' elide t =
unlines $ [descriptionline]
++ commentlines
++ (metadataAsLines $ tmetadata t)
++ (tagsAsLines $ ttags t)
++ (postingsAsLines elide t (tpostings t))
++ [""]
where
@ -163,7 +163,7 @@ postingAsLines :: Bool -> [Posting] -> Posting -> [String]
postingAsLines elideamount ps p =
postinglines
++ commentlines
++ metadataAsLines (pmetadata p)
++ tagsAsLines (ptags p)
where
postinglines = map rstrip $ lines $ concatTopPadded [showacct p, " ", amount, firstcomment]
amount = if elideamount then "" else showamt (pamount p)
@ -186,7 +186,7 @@ tests_postingAsLines = [
pamount=Mixed [dollars 1, hours 2],
pcomment="pcomment1\npcomment2\n",
ptype=RegularPosting,
pmetadata=[("ptag1","val1"),("ptag2","val2")]
ptags=[("ptag1","val1"),("ptag2","val2")]
}
`gives` [
" $1.00",

View File

@ -95,7 +95,7 @@ data Posting = Posting {
pamount :: MixedAmount,
pcomment :: String, -- ^ this posting's non-tag comment lines, as a single non-indented string
ptype :: PostingType,
pmetadata :: [(String,String)],
ptags :: [(String,String)],
ptransaction :: Maybe Transaction -- ^ this posting's parent transaction (co-recursive types).
-- Tying this knot gets tedious, Maybe makes it easier/optional.
}
@ -112,7 +112,7 @@ data Transaction = Transaction {
tcode :: String,
tdescription :: String,
tcomment :: String, -- ^ this transaction's non-tag comment lines, as a single non-indented string
tmetadata :: [(String,String)],
ttags :: [(String,String)],
tpostings :: [Posting], -- ^ this transaction's postings (co-recursive types).
tpreceding_comment_lines :: String
} deriving (Eq)

View File

@ -436,7 +436,7 @@ transactionFromCsvRecord rules fields =
tdescription=newdesc,
tcomment=comment,
tpreceding_comment_lines=precomment,
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -444,7 +444,7 @@ transactionFromCsvRecord rules fields =
pamount=a,
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Just t
},
Posting {
@ -453,7 +453,7 @@ transactionFromCsvRecord rules fields =
pamount=(-baseamount),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Just t
}
]

View File

@ -312,7 +312,7 @@ transaction = do
edate <- optionMaybe (effectivedate date) <?> "effective date"
status <- status <?> "cleared flag"
code <- code <?> "transaction code"
-- now there can be whitespace followed by a description and/or comment/metadata comment
-- now there can be whitespace followed by a description and/or comment/tag comment
let pdescription = many (noneOf ";\n") >>= return . strip
(description, inlinecomment, inlinemd) <-
try (do many1 spacenonewline
@ -340,7 +340,7 @@ tests_transaction = [
same tcode
same tdescription
same tcomment
same tmetadata
same ttags
same tpreceding_comment_lines
same tpostings
-- "0000/01/01\n\n" `gives` nulltransaction
@ -361,7 +361,7 @@ tests_transaction = [
tcode="code",
tdescription="desc",
tcomment="tcomment1\ntcomment2\n",
tmetadata=[("ttag1","val1")],
ttags=[("ttag1","val1")],
tpostings=[
nullposting{
pstatus=True,
@ -369,7 +369,7 @@ tests_transaction = [
pamount=Mixed [dollars 1],
pcomment="pcomment1\npcomment2\n",
ptype=RegularPosting,
pmetadata=[("ptag1","val1"),("ptag2","val2")],
ptags=[("ptag1","val1"),("ptag2","val2")],
ptransaction=Nothing
}
],
@ -465,8 +465,7 @@ status = try (do { many spacenonewline; char '*' <?> "status"; return True } ) <
code :: GenParser Char JournalContext String
code = try (do { many1 spacenonewline; char '(' <?> "code"; code <- anyChar `manyTill` char ')'; return code } ) <|> return ""
-- Parse the following whitespace-beginning lines as postings, posting metadata, and/or comments.
-- complicated to handle intermixed comment and metadata lines.. make me better ?
-- Parse the following whitespace-beginning lines as postings, posting tags, and/or comments.
postings :: GenParser Char JournalContext [Posting]
postings = many1 (try posting) <?> "postings"
@ -505,7 +504,7 @@ tests_posting = [
same pamount
same pcomment
same ptype
same pmetadata
same ptags
same ptransaction
" expenses:food:dining $10.00 ; a: a a \n ; b: b b \n"
`gives`
@ -769,7 +768,7 @@ tests_inlinecomment = [
commentlines :: GenParser Char JournalContext ([String],[Tag])
commentlines = do
comormds <- many $ choice' [(liftM Right metadataline)
comormds <- many $ choice' [(liftM Right tagline)
,(do {many1 spacenonewline; c <- comment; newline; return $ Left c }) -- XXX fix commentnewline
]
return $ partitionEithers comormds
@ -781,10 +780,10 @@ tests_commentlines = [
`gives` (["comment 1","comment 2"],[("tag1","val1")])
]
-- a comment line containing a metadata declaration, eg:
-- a comment line containing a tag declaration, eg:
-- ; name: value
metadataline :: GenParser Char JournalContext (String,String)
metadataline = do
tagline :: GenParser Char JournalContext (String,String)
tagline = do
many1 spacenonewline
md <- tagcomment
newline
@ -800,7 +799,7 @@ tagcomment = do
many spacenonewline
value <- many (noneOf "\n")
return (name, rstrip value)
<?> "metadata comment"
<?> "tag comment"
tests_tagcomment = [
"tagcomment" ~: do

View File

@ -914,7 +914,7 @@ Right samplejournal2 = journalBalanceTransactions $ Journal
tcode="",
tdescription="income",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -922,7 +922,7 @@ Right samplejournal2 = journalBalanceTransactions $ Journal
pamount=(Mixed [dollars 1]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -931,7 +931,7 @@ Right samplejournal2 = journalBalanceTransactions $ Journal
pamount=(missingmixedamt),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],

View File

@ -347,7 +347,7 @@ journal7 = Journal
tcode="*",
tdescription="opening balance",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -355,7 +355,7 @@ journal7 = Journal
pamount=(Mixed [dollars 4.82]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -364,7 +364,7 @@ journal7 = Journal
pamount=(Mixed [dollars (-4.82)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -378,7 +378,7 @@ journal7 = Journal
tcode="*",
tdescription="ayres suites",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -386,7 +386,7 @@ journal7 = Journal
pamount=(Mixed [dollars 179.92]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -395,7 +395,7 @@ journal7 = Journal
pamount=(Mixed [dollars (-179.92)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -409,7 +409,7 @@ journal7 = Journal
tcode="*",
tdescription="auto transfer to savings",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -417,7 +417,7 @@ journal7 = Journal
pamount=(Mixed [dollars 200]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -426,7 +426,7 @@ journal7 = Journal
pamount=(Mixed [dollars (-200)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -440,7 +440,7 @@ journal7 = Journal
tcode="*",
tdescription="poquito mas",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -448,7 +448,7 @@ journal7 = Journal
pamount=(Mixed [dollars 4.82]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -457,7 +457,7 @@ journal7 = Journal
pamount=(Mixed [dollars (-4.82)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -471,7 +471,7 @@ journal7 = Journal
tcode="*",
tdescription="verizon",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -479,7 +479,7 @@ journal7 = Journal
pamount=(Mixed [dollars 95.11]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -488,7 +488,7 @@ journal7 = Journal
pamount=(Mixed [dollars (-95.11)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],
@ -502,7 +502,7 @@ journal7 = Journal
tcode="*",
tdescription="discover",
tcomment="",
tmetadata=[],
ttags=[],
tpostings=[
Posting {
pstatus=False,
@ -510,7 +510,7 @@ journal7 = Journal
pamount=(Mixed [dollars 80]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
},
Posting {
@ -519,7 +519,7 @@ journal7 = Journal
pamount=(Mixed [dollars (-80)]),
pcomment="",
ptype=RegularPosting,
pmetadata=[],
ptags=[],
ptransaction=Nothing
}
],