-
Notifications
You must be signed in to change notification settings - Fork 18
/
filter.go
38 lines (33 loc) · 814 Bytes
/
filter.go
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
package main
const (
FILTER_ONLY string = "only"
FILTER_IGNORE string = "ignore"
)
type Filter struct {
filterType string
pokemonIds []int
}
func (filter *Filter) IsAllowed(id int) bool {
found := false
for _, pokemonId := range filter.pokemonIds {
if pokemonId == id {
found = true
break
}
}
return found == (filter.filterType == FILTER_ONLY)
}
func NewFilter(filterType string, pokemonIds []int) Filter {
return Filter{filterType, pokemonIds}
}
func NewFilterFromPokedexNames(filterType string, pokedex Pokedex, names []string) (Filter, error) {
ids := make([]int, len(names))
for index, name := range names {
pokedexPokemon, err := pokedex.GetByName(name)
if err != nil {
return Filter{}, err
}
ids[index] = pokedexPokemon.Index
}
return NewFilter(filterType, ids), nil
}