-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.go
73 lines (63 loc) · 1.38 KB
/
component.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 (
"sort"
"strconv"
"strings"
)
type component struct {
Refdes []string
Device string
Footprint string
Value string
}
func NewComponent(in []string) component {
var out component
for _, line := range in {
if strings.Contains(line, "=") {
switch line[:strings.Index(line, "=")] {
case "refdes":
out.Refdes = make([]string, 0, 1)
out.Refdes = append(out.Refdes, line[strings.Index(line, "=")+1:])
case "device":
out.Device = line[strings.Index(line, "=")+1:]
case "footprint":
out.Footprint = line[strings.Index(line, "=")+1:]
case "value":
out.Value = line[strings.Index(line, "=")+1:]
}
}
}
return out
}
func (c *component) AddRefdes(refdes string) {
c.Refdes = append(c.Refdes, refdes)
}
func (c component) GetRefdesAsString() string {
sort.Strings(c.Refdes)
res := ""
for _, r := range c.Refdes {
if res != "" {
res += ", "
}
res += r
}
return res
}
func (c component) GetFieldsValues(fieldNames []string) []string {
res := make([]string, 0, len(fieldNames))
for _, f := range fieldNames {
switch f {
case "Device":
res = append(res, c.Device)
case "Refdes":
res = append(res, c.GetRefdesAsString())
case "Footprint":
res = append(res, c.Footprint)
case "Value":
res = append(res, c.Value)
case "Count":
res = append(res, strconv.Itoa(len(c.Refdes)))
}
}
return res
}