-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
condition_type.go
95 lines (82 loc) · 2.53 KB
/
condition_type.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2017 Andrey Gayvoronsky <plandem@gmail.com>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package primitives
import (
"encoding/xml"
)
//ConditionType is a direct mapping of XSD ST_CfType
type ConditionType byte
//ConditionType maps for marshal/unmarshal process
var (
toConditionType map[string]ConditionType
fromConditionType map[ConditionType]string
)
//List of all possible values for Type
const (
_ ConditionType = iota
ConditionTypeExpression
ConditionTypeCellIs
ConditionTypeColorScale
ConditionTypeDataBar
ConditionTypeIconSet
ConditionTypeTop10
ConditionTypeUniqueValues
ConditionTypeDuplicateValues
ConditionTypeContainsText
ConditionTypeNotContainsText
ConditionTypeBeginsWith
ConditionTypeEndsWith
ConditionTypeContainsBlanks
ConditionTypeNotContainsBlanks
ConditionTypeContainsErrors
ConditionTypeNotContainsErrors
ConditionTypeTimePeriod
ConditionTypeAboveAverage
)
func init() {
fromConditionType = map[ConditionType]string{
ConditionTypeExpression: "expression",
ConditionTypeCellIs: "cellIs",
ConditionTypeColorScale: "colorScale",
ConditionTypeDataBar: "dataBar",
ConditionTypeIconSet: "iconSet",
ConditionTypeTop10: "top10",
ConditionTypeUniqueValues: "uniqueValues",
ConditionTypeDuplicateValues: "duplicateValues",
ConditionTypeContainsText: "containsText",
ConditionTypeNotContainsText: "notContainsText",
ConditionTypeBeginsWith: "beginsWith",
ConditionTypeEndsWith: "endsWith",
ConditionTypeContainsBlanks: "containsBlanks",
ConditionTypeNotContainsBlanks: "notContainsBlanks",
ConditionTypeContainsErrors: "containsErrors",
ConditionTypeNotContainsErrors: "notContainsErrors",
ConditionTypeTimePeriod: "timePeriod",
ConditionTypeAboveAverage: "aboveAverage",
}
toConditionType = make(map[string]ConditionType, len(fromConditionType))
for k, v := range fromConditionType {
toConditionType[v] = k
}
}
func (t ConditionType) String() string {
return fromConditionType[t]
}
//MarshalXMLAttr marshal ConditionType
func (t *ConditionType) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
attr := xml.Attr{Name: name}
if v, ok := fromConditionType[*t]; ok {
attr.Value = v
} else {
attr = xml.Attr{}
}
return attr, nil
}
//UnmarshalXMLAttr unmarshal ConditionType
func (t *ConditionType) UnmarshalXMLAttr(attr xml.Attr) error {
if v, ok := toConditionType[attr.Value]; ok {
*t = v
}
return nil
}