{-|
A 'Commodity' is a symbol representing a currency or some other kind of
thing we are tracking, and some display preferences that tell how to
display 'Amount's of the commodity - is the symbol on the left or right,
are thousands separated by comma, significant decimal places and so on.
-}moduleHledger.Data.CommoditywhereimportData.ListimportData.Map((!))importData.MaybeimportTest.HUnitimportqualifiedData.MapasMapimportHledger.Data.TypesimportHledger.Utilsnonsimplecommoditychars="0123456789-.@;\n \""quoteCommoditySymbolIfNeededs|any(`elem`nonsimplecommoditychars)s="\""++s++"\""|otherwise=s-- convenient amount and commodity constructors, for tests etc.unknown=Commodity{symbol="",side=L,spaced=False,decimalpoint='.',precision=0,separator=',',separatorpositions=[]}dollar=Commodity{symbol="$",side=L,spaced=False,decimalpoint='.',precision=2,separator=',',separatorpositions=[]}euro=Commodity{symbol="€",side=L,spaced=False,decimalpoint='.',precision=2,separator=',',separatorpositions=[]}pound=Commodity{symbol="£",side=L,spaced=False,decimalpoint='.',precision=2,separator=',',separatorpositions=[]}hour=Commodity{symbol="h",side=R,spaced=False,decimalpoint='.',precision=1,separator=',',separatorpositions=[]}dollarsn=AmountdollarnNothingeurosn=AmounteuronNothingpoundsn=AmountpoundnNothinghoursn=AmounthournNothingdefaultcommodities=[dollar,euro,pound,hour,unknown]-- | Look up one of the hard-coded default commodities. For use in tests.comm::String->Commoditycommsym=fromMaybe(error'"commodity lookup failed")$find(\(Commodity{symbol=s})->s==sym)defaultcommodities-- | Find the conversion rate between two commodities. Currently returns 1.conversionRate::Commodity->Commodity->DoubleconversionRate__=1-- | Convert a list of commodities to a map from commodity symbols to-- unique, display-preference-canonicalised commodities.canonicaliseCommodities::[Commodity]->Map.MapStringCommoditycanonicaliseCommoditiescs=Map.fromList[(s,firstc{precision=maxp})|s<-symbols,letcs=commoditymap!s,letfirstc=headcs,letmaxp=maximum$mapprecisioncs]wherecommoditymap=Map.fromList[(s,commoditieswithsymbols)|s<-symbols]commoditieswithsymbols=filter((s==).symbol)cssymbols=nub$mapsymbolcstests_Hledger_Data_Commodity=TestList[]