From 8c663269b4a2981fd35b60dcaad8ba2de9915dc2 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 12 Jun 2014 17:24:14 -0400 Subject: [PATCH] Add an (un)pickler for the AutoRacingResults earnings (unfinished). --- src/TSN/Picklers.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/TSN/Picklers.hs b/src/TSN/Picklers.hs index dc3ed9a..387f4cf 100644 --- a/src/TSN/Picklers.hs +++ b/src/TSN/Picklers.hs @@ -4,6 +4,7 @@ module TSN.Picklers ( xp_date, xp_date_padded, + xp_earnings, xp_gamedate, xp_racedate, xp_tba_time, @@ -12,6 +13,7 @@ module TSN.Picklers ( where -- System imports. +import Data.String.Utils ( replace ) import Data.Time.Clock ( NominalDiffTime, UTCTime, addUTCTime ) import Data.Time.Format ( formatTime, parseTime ) import System.Locale ( defaultTimeLocale ) @@ -76,6 +78,30 @@ xp_date_padded = from_date = formatTime defaultTimeLocale date_format_padded +-- | Parse \ from an 'AutoRaceResultsListing'. These are +-- essentially 'Int's, but they look like, +-- +-- * 336,826 +-- * 1,000,191 +-- * TBA +-- +xp_earnings :: PU (Maybe Int) +xp_earnings = + (to_earnings, from_earnings) `xpWrap` xpText + where + strip_commas :: String -> String + strip_commas = replace "," "" + + to_earnings :: String -> Maybe Int + to_earnings s + | s == "TBA" = Nothing + | otherwise = (read . strip_commas . show) s + + from_earnings :: Maybe Int -> String + from_earnings Nothing = "" + from_earnings (Just i) = show i + + -- | (Un)pickle a 'UTCTime' from a \ element in an -- 'AutoRaceResults' message. -- -- 2.44.2