-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection.go
69 lines (56 loc) · 1.1 KB
/
selection.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package velux
// WindowSelection matches windows with matching attributes
type WindowSelection struct {
Codes []string
Serials []string
Types []WindowType
}
// Matches checks if the provided window matches the selection's attributes.
func (w *WindowSelection) Matches(info *WindowInfo) bool {
if !w.codeMatch(info) {
return false
}
if !w.serialMatch(info) {
return false
}
if !w.typeMatch(info) {
return false
}
return true
}
func (w *WindowSelection) codeMatch(info *WindowInfo) bool {
if len(w.Codes) == 0 {
return true
}
if info.Mapping == nil {
return false
}
for _, code := range w.Codes {
if code == info.Mapping.Code {
return true
}
}
return false
}
func (w *WindowSelection) serialMatch(info *WindowInfo) bool {
if len(w.Serials) == 0 {
return true
}
for _, serial := range w.Serials {
if serial == info.SerialNumber {
return true
}
}
return false
}
func (w *WindowSelection) typeMatch(info *WindowInfo) bool {
if len(w.Types) == 0 {
return true
}
for _, wType := range w.Types {
if wType == info.WindowType {
return true
}
}
return false
}