-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
not_matches.go
39 lines (31 loc) · 927 Bytes
/
not_matches.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
package distil
import (
"fmt"
"reflect"
"strings"
)
type notMatches struct {
rows []map[string]interface{}
}
func (a *notMatches) Filter(row map[string]interface{}, filter *Filter) error {
// Check filter.Value datatypes can be used with our filter.Operator.
err := validateDataType(filter)
if err != nil {
return err
}
// Ensure the value passed is of datatype string.
if reflect.TypeOf(row[filter.Field]).String() != operatorTypeString {
return fmt.Errorf("Invalid datatype. Expected string datatype for `%v`, got %T", filter.Field, row[filter.Field])
}
// Ensure values are matched case-insensitive.
s, substr := strings.ToUpper(row[filter.Field].(string)), strings.ToUpper(filter.Value.(string))
// Match.
if !strings.Contains(s, substr) {
a.rows = append(a.rows, row)
}
return nil
}
// Result implements distiller().
func (a *notMatches) Result() []map[string]interface{} {
return a.rows
}