forked from nyaruka/goflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locations.go
48 lines (37 loc) · 1.29 KB
/
locations.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
package flows
import (
"strings"
"github.com/nyaruka/goflow/excellent/types"
"github.com/nyaruka/goflow/utils"
)
// location levels which can be field types
const (
LocationLevelState = utils.LocationLevel(1)
LocationLevelDistrict = utils.LocationLevel(2)
LocationLevelWard = utils.LocationLevel(3)
)
// LocationPath is a location described by a path Country > State ...
type LocationPath string
// IsPossibleLocationPath returns whether the given string could be a location path
func IsPossibleLocationPath(str string) bool {
return strings.Contains(str, utils.LocationPathSeparator)
}
// Name returns the name of the location referenced
func (p LocationPath) Name() string {
parts := strings.Split(string(p), utils.LocationPathSeparator)
return strings.TrimSpace(parts[len(parts)-1])
}
func (p LocationPath) String() string {
return string(p)
}
// Describe returns a representation of this type for error messages
func (p LocationPath) Describe() string { return "location" }
// Reduce returns the primitive version of this type
func (p LocationPath) Reduce() types.XPrimitive {
return types.NewXText(string(p))
}
// ToXJSON is called when this type is passed to @(json(...))
func (p LocationPath) ToXJSON() types.XText {
return p.Reduce().ToXJSON()
}
var _ types.XValue = LocationPath("")