Model search criteria
This commit is contained in:
parent
3aabb35da5
commit
a2434a2306
3 changed files with 75 additions and 0 deletions
71
Search.hs
Normal file
71
Search.hs
Normal file
|
@ -0,0 +1,71 @@
|
|||
module Search
|
||||
( colors,
|
||||
colorless,
|
||||
parse
|
||||
)
|
||||
where
|
||||
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Text as T
|
||||
|
||||
data Search = Search [Criteria] deriving (Show)
|
||||
|
||||
data Criteria
|
||||
= NameContains T.Text
|
||||
| ExpansionCodeIs T.Text
|
||||
| CardTypeContains T.Text
|
||||
| OracleTextContains T.Text
|
||||
| ColorIdentityIs Colors
|
||||
| ColorIdentityGTE Colors
|
||||
| ColorIdentityLTE Colors
|
||||
| RarityIs Rarity
|
||||
| RarityGTE Rarity
|
||||
| RarityLTE Rarity
|
||||
deriving (Show)
|
||||
|
||||
data Color
|
||||
= Colorless
|
||||
| White
|
||||
| Black
|
||||
| Blue
|
||||
| Green
|
||||
| Red
|
||||
deriving (Eq, Ord)
|
||||
|
||||
instance Show Color where
|
||||
show White = "W"
|
||||
show Black = "B"
|
||||
show Blue = "U"
|
||||
show Green = "G"
|
||||
show Red = "R"
|
||||
|
||||
newtype Colors
|
||||
= Colors (Set.Set Color)
|
||||
|
||||
instance Show Colors where
|
||||
show (Colors xs) =
|
||||
mconcat
|
||||
[ "{",
|
||||
mconcat $
|
||||
map show $
|
||||
Set.elems xs,
|
||||
"}"
|
||||
]
|
||||
|
||||
data Rarity
|
||||
= Common
|
||||
| Uncommon
|
||||
| Rare
|
||||
| Mythic
|
||||
deriving (Eq, Ord, Show)
|
||||
|
||||
colors :: [Color] -> Colors
|
||||
colors = Colors . Set.fromList
|
||||
|
||||
colorless :: Colors -> Bool
|
||||
colorless (Colors xs)
|
||||
| Set.null xs = True
|
||||
| otherwise = False
|
||||
|
||||
parse :: T.Text -> Search
|
||||
parse _ = Search []
|
|
@ -21,6 +21,7 @@ description: Please see the README on GitHub at <https://github.com/gith
|
|||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- aeson
|
||||
- containers
|
||||
- lens
|
||||
- openapi3
|
||||
- servant-openapi3
|
||||
|
|
|
@ -31,6 +31,7 @@ library
|
|||
build-depends:
|
||||
aeson
|
||||
, base >=4.7 && <5
|
||||
, containers
|
||||
, lens
|
||||
, openapi3
|
||||
, servant-openapi3
|
||||
|
@ -52,6 +53,7 @@ executable tutor-exe
|
|||
build-depends:
|
||||
aeson
|
||||
, base
|
||||
, containers
|
||||
, lens
|
||||
, openapi3
|
||||
, servant-openapi3
|
||||
|
@ -75,6 +77,7 @@ test-suite tutor-test
|
|||
build-depends:
|
||||
aeson
|
||||
, base
|
||||
, containers
|
||||
, hspec
|
||||
, hspec-wai
|
||||
, hspec-wai-json
|
||||
|
|
Loading…
Reference in a new issue