blob: f12936f8facdc4220aa864cdd8062e34ea2c0639 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
{-# LANGUAGE OverloadedStrings #-}
module Model.Perfume
( Perfume(..)
, csvPerfumes
, mergePerfumes
, fileName
) where
import Data.Text (Text)
import qualified Data.Text as T
import CommandLineOptions (Options(..))
import Model.URL
import CSV
data Perfume = Perfume
{ name :: Text
, url :: URL
} deriving (Eq, Show)
csvPerfumes :: [Perfume] -> Text
csvPerfumes = getCsv . map (\perfume -> [name perfume, url perfume])
mergePerfumes :: [[Perfume]] -> [[Perfume]] -> [Perfume]
mergePerfumes (perfumes1:perfumesSequences) (ignoredPerfumesSequences) =
filter
(\p1 ->
( all
(\perfumes2 ->
any
(\p2 -> name p1 == name p2)
perfumes2
)
perfumesSequences
&& all
(\perfumes2 ->
all
(\p2 -> name p1 /= name p2)
perfumes2
)
ignoredPerfumesSequences
)
)
perfumes1
fileName :: Options -> Text
fileName (Options materials ignoredMaterials) =
let materialNames = T.intercalate "-" materials
ignoredMaterialNames = T.intercalate "-" ignoredMaterials
in if null ignoredMaterials
then materialNames
else T.concat [materialNames, "-without-", ignoredMaterialNames]
|