-
Notifications
You must be signed in to change notification settings - Fork 5
/
attribute.go
52 lines (43 loc) · 1.33 KB
/
attribute.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
package sandbox
import "strconv"
// Attribute describes an attribute on a sandbox profile
type Attribute struct {
Name string `json:"name"`
Value string `json:"value"`
Derivation string `json:"derivation"`
Optional string `json:"optional"`
Anchors []Anchor `json:"anchors"`
}
// Derivation is a builder for derivation strings
type Derivation struct {
value string
}
// WithName sets the value of a Sandbox Attribute
func (attr Attribute) WithName(name string) Attribute {
attr.Name = name
return attr
}
// WithValue sets the value of a Sandbox Attribute
func (attr Attribute) WithValue(value string) Attribute {
attr.Value = value
return attr
}
// WithAnchor sets the Anchor of a Sandbox Attribute
func (attr Attribute) WithAnchor(anchor Anchor) Attribute {
attr.Anchors = append(attr.Anchors, anchor)
return attr
}
// ToString returns the string representation for a derivation
func (derivation Derivation) ToString() string {
return derivation.value
}
// AgeOver builds an age over age derivation
func (derivation Derivation) AgeOver(age int) Derivation {
derivation.value = "age_over:" + strconv.Itoa(age)
return derivation
}
// AgeUnder builds an age under age derivation
func (derivation Derivation) AgeUnder(age int) Derivation {
derivation.value = "age_under:" + strconv.Itoa(age)
return derivation
}