Multiple regions and types filtering

This commit is contained in:
Samuel Henrique Oliveira da Silva 2017-10-09 09:45:10 -03:00
parent 9e4536657e
commit b245861fa8
2 changed files with 9 additions and 8 deletions

View file

@ -24,6 +24,7 @@ _filters_group.add_argument(
help='Filter the pokemons by region',
action=filters.RegionFilter,
choices=Database.REGIONS,
nargs='*',
type=str.lower)
_filters_group.add_argument(
'-l',
@ -53,6 +54,7 @@ _filters_group.add_argument(
help='Filter the pokemons by type.',
action=filters.TypeFilter,
choices=Database.POKEMON_TYPES,
nargs='*',
type=str.lower)
_filters_group.add_argument(
'-ne',

View file

@ -27,10 +27,10 @@ class NameFilter(Filter):
class RegionFilter(Filter):
EXAMPLE_VAL = 'kanto'
EXAMPLE_VAL = ['kanto']
def matches(self, pokemon: Pokemon, value: str):
return pokemon.get_region() == value
def matches(self, pokemon: Pokemon, value: list):
return pokemon.get_region() in value
class LightFilter(Filter):
@ -48,12 +48,11 @@ class DarkFilter(Filter):
class TypeFilter(Filter):
EXAMPLE_VAL = 'water'
EXAMPLE_VAL = ['water']
def matches(self, pokemon: Pokemon, value: str):
value = value.lower()
return value in (pokemon.get_pkmn_type(),
pokemon.get_pkmn_type_secondary())
def matches(self, pokemon: Pokemon, value: list):
return pokemon.get_pkmn_type() in value or \
pokemon.get_pkmn_type_secondary() in value
class NonExtrasFilter(Filter):