forked from offenesdresden/dvbgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeparture.go
40 lines (35 loc) · 809 Bytes
/
departure.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
package dvb
import (
"fmt"
"strconv"
)
// Departure encapsulates info regarding the line, direction and relative departure time in minutes.
type Departure struct {
Line string
Direction string
RelativeTime int
}
func (dep Departure) String() string {
return fmt.Sprintf("%s %s in %d minutes", dep.Line, dep.Direction, dep.RelativeTime)
}
// Mode returns the departure's mode of transport
func (dep Departure) Mode() (mode TransportMode, err error) {
return parseMode(dep.Line)
}
func initDeparture(attrs []string) (departure *Departure, err error) {
var rel int
if attrs[2] == "" {
rel = 0
} else {
rel, err = strconv.Atoi(attrs[2])
if err != nil {
return
}
}
departure = &Departure{
Line: attrs[0],
Direction: attrs[1],
RelativeTime: rel,
}
return
}