-
Notifications
You must be signed in to change notification settings - Fork 1
/
matches_filter.go
54 lines (41 loc) · 1.29 KB
/
matches_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import "strings"
type MatchesFilter interface {
TakeMatch(m Match) bool
}
// FilterTodayMatches takes only today matches.
type FilterTodayMatches struct {
filter MatchesFilter
}
func NewFilterTodayMatches(filter MatchesFilter) MatchesFilter {
return &FilterTodayMatches{filter}
}
func (f *FilterTodayMatches) TakeMatch(m Match) bool {
return f.filter.TakeMatch(m) && m.IsToday()
}
// StarredFilter takes only starred matches.
type StarredFilter struct {
filter MatchesFilter
}
func NewStarredFilter(filter MatchesFilter) MatchesFilter {
return &StarredFilter{filter}
}
// TakeMatch takes matches with given team.
func (f *StarredFilter) TakeMatch(m Match) bool {
return f.filter.TakeMatch(m) && m.Stars > 0
}
type TeamFilter struct {
filter MatchesFilter
team string
}
func NewTeamFilter(filter MatchesFilter, team string) MatchesFilter {
return &TeamFilter{filter: filter, team: strings.ToLower(team)}
}
func (f *TeamFilter) TakeMatch(m Match) bool {
return f.filter.TakeMatch(m) &&
(strings.Contains(strings.ToLower(m.FirstTeam), f.team) ||
strings.Contains(strings.ToLower(m.SecondTeam), f.team))
}
// TakeEveryMatchFilter default filter which takes all matches.
type TakeEveryMatchFilter struct{}
func (f *TakeEveryMatchFilter) TakeMatch(m Match) bool { return true }