-
Notifications
You must be signed in to change notification settings - Fork 0
/
band.go
67 lines (55 loc) · 944 Bytes
/
band.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
package main
import (
"regexp"
"strings"
)
type BandI interface {
Store() error
}
type Band struct {
Name string
State State
Stage string
}
type State int
const (
Rumoured State = iota
StronglyRumoured
TBC
Confirmed
)
func (s State) String() string {
switch s {
case Rumoured:
return "Rumoured"
case StronglyRumoured:
return "Strongly Rumoured"
case TBC:
return "TBC"
case Confirmed:
return "Confirmed"
}
return "unknown"
}
func extractBandFromInputString(input string) Band {
r := regexp.MustCompile(` (?P<Date>.+), (?P<Stage>.+)\((?P<State>.+)\) (?P<Name>.+)`)
found := r.FindStringSubmatch(input)
name := strings.Join(strings.Fields(found[4]), " ")
stage := found[2]
var state State
switch found[3] {
case "R":
state = Rumoured
case "SR":
state = StronglyRumoured
case "TBC":
state = TBC
case "C":
state = Confirmed
}
return Band{
Name: name,
State: state,
Stage: stage,
}
}