/
filter-base.go
67 lines (52 loc) 路 1.44 KB
/
filter-base.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
package nav
import (
"github.com/samber/lo"
)
// Filter =====================================================================
// Filter base filter struct.
type Filter struct {
name string
pattern string
scope FilterScopeBiEnum // defines which file system nodes the filter should be applied to
negate bool // select to define a negative match
ifNotApplicable bool
}
// Description description of the filter
func (f *Filter) Description() string {
return f.name
}
// Source text defining the filter
func (f *Filter) Source() string {
return f.pattern
}
func (f *Filter) IsApplicable(item *TraverseItem) bool {
return (f.scope & item.Extension.NodeScope) > 0
}
func (f *Filter) Scope() FilterScopeBiEnum {
return f.scope
}
func (f *Filter) invert(result bool) bool {
return lo.Ternary(f.negate, !result, result)
}
func (f *Filter) Validate() {
if f.scope == ScopeUndefinedEn {
f.scope = ScopeAllEn
}
}
// CompoundFilter =============================================================
// CompoundFilter filter used when subscription is FoldersWithFiles
type CompoundFilter struct {
Name string
Pattern string
Negate bool
}
func (f *CompoundFilter) Description() string {
return f.Name
}
func (f *CompoundFilter) Validate() {}
func (f *CompoundFilter) Source() string {
return f.Pattern
}
func (f *CompoundFilter) invert(result bool) bool {
return lo.Ternary(f.Negate, !result, result)
}