-
Notifications
You must be signed in to change notification settings - Fork 0
/
runontext.go
69 lines (60 loc) · 2.13 KB
/
runontext.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
package types
import "github.com/pkg/errors"
// WithUndefinedRunonText is a compositing type for parsing the `utxt` property
type WithUndefinedRunonText struct {
UndefinedRunonText *UndefinedRunonText `json:"utxt,omitempty"`
}
// UndefinedRunonText https://dictionaryapi.com/products/json#sec-2.uros
type UndefinedRunonText SequenceMapping
// UndefinedRunonTextItemType is an enum type for the types of items in UndefinedRunonText
type UndefinedRunonTextItemType int
// Values for UndefinedRunonTextItemType
const (
UndefinedRunonTextItemTypeUnknown = iota
UndefinedRunonTextItemTypeVerbalIllustrations
UndefinedRunonTextItemTypeUsageNotes
)
// UndefinedRunonTextItemTypeFromString returns a UndefinedRunonTextItemType from its string ID
func UndefinedRunonTextItemTypeFromString(id string) UndefinedRunonTextItemType {
switch id {
case "vis":
return UndefinedRunonTextItemTypeVerbalIllustrations
case "uns":
return UndefinedRunonTextItemTypeUsageNotes
default:
return UndefinedRunonTextItemTypeUnknown
}
}
func (t UndefinedRunonTextItemType) String() string {
return []string{"", "vis", "uns"}[t]
}
// Contents returns a copied slice of the contents in the UndefinedRunonText
func (uro UndefinedRunonText) Contents() ([]UndefinedRunonTextItem, error) {
items := []UndefinedRunonTextItem{}
for _, el := range uro {
key, err := el.Key()
if err != nil {
return nil, err
}
typ := UndefinedRunonTextItemTypeFromString(key)
switch typ {
case UndefinedRunonTextItemTypeVerbalIllustrations:
var out []VerbalIllustration
err = el.UnmarshalValue(&out)
items = append(items, UndefinedRunonTextItem{Type: typ, WithVerbalIllustrations: WithVerbalIllustrations{out}})
case UndefinedRunonTextItemTypeUsageNotes:
var out []UsageNote
err = el.UnmarshalValue(&out)
items = append(items, UndefinedRunonTextItem{Type: typ, WithUsageNotes: WithUsageNotes{out}})
default:
err = errors.New("unknown item type in verbal illustration")
}
}
return items, nil
}
// UndefinedRunonTextItem is an item of the SI container
type UndefinedRunonTextItem struct {
Type UndefinedRunonTextItemType
WithVerbalIllustrations
WithUsageNotes
}