aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
authorJoris2015-09-01 15:18:57 +0200
committerJoris2015-09-01 15:19:01 +0200
commita45cffb45e751275b30f558109c21d8c6507e07d (patch)
tree6d722f5781f0dac6f134f3d857b3ce0628ebe5e1 /src/Model
parentd528036eae405f335498b57c2907c9269dc1554a (diff)
Add a command line option to ignore materials
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/Perfume.hs39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/Model/Perfume.hs b/src/Model/Perfume.hs
index 0f99b55..f12936f 100644
--- a/src/Model/Perfume.hs
+++ b/src/Model/Perfume.hs
@@ -3,12 +3,15 @@
module Model.Perfume
( Perfume(..)
, csvPerfumes
- , getCommonPerfumes
+ , mergePerfumes
+ , fileName
) where
import Data.Text (Text)
import qualified Data.Text as T
+import CommandLineOptions (Options(..))
+
import Model.URL
import CSV
@@ -21,16 +24,32 @@ data Perfume = Perfume
csvPerfumes :: [Perfume] -> Text
csvPerfumes = getCsv . map (\perfume -> [name perfume, url perfume])
-getCommonPerfumes :: [[Perfume]] -> [Perfume]
-getCommonPerfumes (perfumes1:perfumesSequences) =
+mergePerfumes :: [[Perfume]] -> [[Perfume]] -> [Perfume]
+mergePerfumes (perfumes1:perfumesSequences) (ignoredPerfumesSequences) =
filter
(\p1 ->
- all
- (\perfumes2 ->
- any
- (\p2 -> name p1 == name p2)
- perfumes2
- )
- perfumesSequences
+ ( 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]