aboutsummaryrefslogtreecommitdiff
path: root/src/View/Plain
diff options
context:
space:
mode:
authorJoris2018-06-17 23:24:47 +0200
committerJoris2018-06-18 11:13:55 +0200
commit0a4d3c8f12dc5797a919a00b6bcaf759947687cc (patch)
treebcb89781e22c2314bf0c064ebb37cb7f8a362f5c /src/View/Plain
parente2a5c7c5c596d057b6fa9c08a8204ce1429cfdc4 (diff)
Add ouest france parser
Diffstat (limited to 'src/View/Plain')
-rw-r--r--src/View/Plain/Ad.hs108
1 files changed, 0 insertions, 108 deletions
diff --git a/src/View/Plain/Ad.hs b/src/View/Plain/Ad.hs
deleted file mode 100644
index b9e980e..0000000
--- a/src/View/Plain/Ad.hs
+++ /dev/null
@@ -1,108 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-
-module View.Plain.Ad
- ( renderConsoleAds
- , renderAds
- ) where
-
-import Data.Maybe (fromMaybe, catMaybes)
-import Data.Map (Map)
-import qualified Data.Map as M
-
-import Data.Text (Text)
-import qualified Data.Text as T
-
-import Model.Ad (Ad)
-import qualified Model.Ad as Ad
-
-import Model.Resume (Resume)
-import qualified Model.Resume as Resume
-
-import Model.Detail (Detail)
-import qualified Model.Detail as Detail
-
-import Model.URL (URL)
-import Conf (Conf)
-import qualified Conf
-
-renderConsoleAds :: Conf -> Text -> [Ad] -> Text
-renderConsoleAds conf time ads =
- let (title, message) = renderAds conf ads
- titleWithTime =
- T.concat
- [ "\n["
- , time
- , "] "
- , title
- ]
- line = T.map (\_ -> '-') titleWithTime
- in T.intercalate
- "\n"
- [ titleWithTime
- , line
- , ""
- , message
- ]
-
-renderAds :: Conf -> [Ad] -> (Text, Text)
-renderAds conf ads =
- let titleMessage = renderTitle $ length ads
- adsMessage = T.intercalate "\n\n" . map (renderAd conf) $ ads
- in (titleMessage, adsMessage)
-
-renderTitle :: Int -> Text
-renderTitle count =
- T.concat
- [ T.pack . show $ count
- , agreement " nouvelle"
- , agreement " annonce"
- ]
- where agreement word =
- T.concat
- [ word
- , if count > 1 then "s" else ""
- ]
-
-renderAd :: Conf -> Ad -> Text
-renderAd conf ad =
- T.concat
- [ renderResume (Ad.resume ad)
- , "\n"
- , renderDetail conf (Ad.detail ad)
- ]
-
-renderResume :: Resume -> Text
-renderResume resume =
- let formatPrice price = T.concat [" - ", price]
- getPrice = fromMaybe "" . fmap formatPrice . Resume.price $ resume
- isPro = if Resume.isPro resume then " - PRO" else ""
- titleLine = T.concat [Resume.name resume, getPrice, isPro]
- in T.intercalate "\n" [titleLine, Resume.url resume]
-
-renderDetail :: Conf -> Detail -> Text
-renderDetail conf detail =
- T.concat
- [ renderProperties (Conf.properties conf) (Detail.properties detail)
- , fromMaybe "−" (Detail.description detail)
- , renderURLs "\n\nImages:" (Detail.images detail)
- ]
-
-renderProperties :: [Text] -> Map Text Text -> Text
-renderProperties [] _ = ""
-renderProperties keys properties =
- T.concat
- [ "\n"
- , T.concat (catMaybes $ map (renderProperty properties) keys)
- , "\n"
- ]
-
-renderProperty :: Map Text Text -> Text -> Maybe Text
-renderProperty properties key =
- fmap
- (\value -> T.concat [key, ": ", value, "\n"])
- (M.lookup key properties)
-
-renderURLs :: Text -> [URL] -> Text
-renderURLs _ [] = ""
-renderURLs title urls =
- T.intercalate "\n" (title:urls)