-
Notifications
You must be signed in to change notification settings - Fork 36
/
global.go
73 lines (63 loc) · 1.39 KB
/
global.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
package main
import (
"fmt"
"path/filepath"
"strings"
)
const globalTemplate = `###
### Delivered by puppet
###
# Defines the channel code of the preferred stream used eg by scautopick and
# scrttv. If no component code is given, 'Z' will be used by default.
detecStream = {{.Stream}}
# Defines the location code of the preferred stream used eg by scautopick and
# scrttv.
detecLocid = {{.Location}}
`
type Global struct {
Stream string
Location string
}
func (p Global) Id() string {
return "global"
}
func (p Global) Template() string {
return globalTemplate
}
func (p Global) Style() string {
switch {
case strings.HasPrefix(p.Stream, "HH"):
return "broadband"
case strings.HasPrefix(p.Stream, "EH"):
return "weak"
case strings.HasPrefix(p.Stream, "SH"):
return "weak"
case strings.HasPrefix(p.Stream, "HN"):
return "strong"
case strings.HasPrefix(p.Stream, "BN"):
return "strong"
default:
return ""
}
}
func (p Global) Rate() string {
switch {
case strings.HasPrefix(p.Stream, "B"):
return "lowrate"
case strings.HasPrefix(p.Stream, "S"):
return "lowrate"
default:
return ""
}
}
func (p Global) Key() string {
switch r := p.Rate(); r {
case "":
return fmt.Sprintf("%s_%s", p.Style(), p.Location)
default:
return fmt.Sprintf("%s_%s_%s", p.Style(), r, p.Location)
}
}
func (p Global) Path() string {
return filepath.Join(p.Id(), fmt.Sprintf("profile_%s", p.Key()))
}