diff options
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/Perfume.hs | 39 |
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] |