commodity cleanup
This commit is contained in:
parent
9f8e0c42fe
commit
93ced249b3
@ -1,9 +1,9 @@
|
|||||||
{-|
|
{-|
|
||||||
|
|
||||||
A 'Commodity' is a symbol representing a currency or some other kind of
|
A 'Commodity' is a symbol representing a currency or some other kind of
|
||||||
thing we are tracking, and some settings that tell how to display amounts
|
thing we are tracking, and some display preferences that tell how to
|
||||||
of the commodity. For the moment, commodities also include a hard-coded
|
display 'Amount's of the commodity - is the symbol on the left or right,
|
||||||
conversion rate relative to the dollar.
|
are thousands separated by comma, significant decimal places and so on.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
module Ledger.Commodity
|
module Ledger.Commodity
|
||||||
@ -13,15 +13,13 @@ import Ledger.Utils
|
|||||||
import Ledger.Types
|
import Ledger.Types
|
||||||
|
|
||||||
|
|
||||||
-- for nullamt, autoamt, etc.
|
|
||||||
unknown = Commodity {symbol="",side=L,spaced=False,comma=False,precision=0}
|
|
||||||
|
|
||||||
-- convenient amount and commodity constructors, for tests etc.
|
-- convenient amount and commodity constructors, for tests etc.
|
||||||
|
|
||||||
dollar = Commodity {symbol="$",side=L,spaced=False,comma=False,precision=2}
|
unknown = Commodity {symbol="", side=L,spaced=False,comma=False,precision=0}
|
||||||
|
dollar = Commodity {symbol="$", side=L,spaced=False,comma=False,precision=2}
|
||||||
euro = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2}
|
euro = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2}
|
||||||
pound = Commodity {symbol="£",side=L,spaced=False,comma=False,precision=2}
|
pound = Commodity {symbol="£", side=L,spaced=False,comma=False,precision=2}
|
||||||
hour = Commodity {symbol="h",side=R,spaced=False,comma=False,precision=1}
|
hour = Commodity {symbol="h", side=R,spaced=False,comma=False,precision=1}
|
||||||
|
|
||||||
dollars n = Amount dollar n Nothing
|
dollars n = Amount dollar n Nothing
|
||||||
euros n = Amount euro n Nothing
|
euros n = Amount euro n Nothing
|
||||||
@ -30,13 +28,13 @@ hours n = Amount hour n Nothing
|
|||||||
|
|
||||||
defaultcommodities = [dollar, euro, pound, hour, unknown]
|
defaultcommodities = [dollar, euro, pound, hour, unknown]
|
||||||
|
|
||||||
defaultcommoditiesmap :: Map.Map String Commodity
|
-- | Look up one of the hard-coded default commodities. For use in tests.
|
||||||
defaultcommoditiesmap = Map.fromList [(symbol c :: String, c :: Commodity) | c <- defaultcommodities]
|
|
||||||
|
|
||||||
comm :: String -> Commodity
|
comm :: String -> Commodity
|
||||||
comm symbol = Map.findWithDefault (error "commodity lookup failed") symbol defaultcommoditiesmap
|
comm sym = fromMaybe
|
||||||
|
(error "commodity lookup failed")
|
||||||
|
$ find (\(Commodity{symbol=s}) -> s==sym) defaultcommodities
|
||||||
|
|
||||||
-- | Find the conversion rate between two commodities.
|
-- | Find the conversion rate between two commodities. Currently returns 1.
|
||||||
conversionRate :: Commodity -> Commodity -> Double
|
conversionRate :: Commodity -> Commodity -> Double
|
||||||
conversionRate oldc newc = 1
|
conversionRate oldc newc = 1
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user