feragstring/route_list.go

95 lines
2.3 KiB
Go
Raw Normal View History

2020-05-27 21:23:36 +02:00
package feragstring
import "fmt"
2020-07-06 20:43:58 +02:00
// RouteListEntry is the struct for one route entry in the
// list of routes
2020-05-27 21:23:36 +02:00
type RouteListEntry struct {
FeragMessage
2020-05-29 14:39:59 +02:00
routeName string
routeCode int
rampNumber int
2020-05-27 21:23:36 +02:00
copiesInRoute int
}
2020-07-06 20:43:58 +02:00
// CopiesInRoute returns the formatted number of copies in the route
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) CopiesInRoute() string {
if r.copiesInRoute == 0 {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+23%06d", r.copiesInRoute)
}
2020-07-06 20:43:58 +02:00
// SetCopiesInRoute set the number of copies in the route
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) SetCopiesInRoute(copiesInRoute int) {
r.copiesInRoute = copiesInRoute
}
2020-07-06 20:43:58 +02:00
// RampNumber returns the formatted ramp number. Segment is
// returned only if the ramp number is set to a value.
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) RampNumber() string {
if r.rampNumber == -1 {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+25%02d", r.rampNumber)
}
2020-07-06 20:43:58 +02:00
// SetRampNumber sets the ramp number field to an integer
// value. A value of 0 is allowed.
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) SetRampNumber(rampNumber int) {
r.rampNumber = rampNumber
}
2020-07-06 20:43:58 +02:00
// RouteCode returns the formatted route code.
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) RouteCode() string {
if r.routeCode == 0 {
return ""
}
2020-05-27 21:23:36 +02:00
return fmt.Sprintf("+79%05d", r.routeCode)
}
2020-07-06 20:43:58 +02:00
// SetRouteCode sets the route code field
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) SetRouteCode(routeCode int) {
r.routeCode = routeCode
}
2020-07-06 20:43:58 +02:00
// RouteName returns the formatted route name.
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) RouteName() string {
return fmt.Sprintf("+11%-13s", r.routeName)
}
2020-07-06 20:43:58 +02:00
// SetRouteName sets the route name field
2020-05-27 21:23:36 +02:00
func (r *RouteListEntry) SetRouteName(routeName string) {
r.routeName = routeName
}
2020-07-06 20:43:58 +02:00
// NewRouteListEntry instantiates a new Route List Entry
// struct and returns a pointer to it.
2020-05-27 21:23:36 +02:00
func NewRouteListEntry() *RouteListEntry {
rl := RouteListEntry{
FeragMessage: FeragMessage{
messageStart: "2401",
messageEnd: "!",
},
rampNumber: -1,
2020-05-27 21:23:36 +02:00
}
return &rl
}
2020-07-06 20:43:58 +02:00
// Payload returns the formatted FERAG string
// for embedding in the message
2020-05-27 21:23:36 +02:00
func (rl *RouteListEntry) Payload() string {
data := rl.RouteName()
data += rl.RouteCode()
data += rl.RampNumber()
data += rl.CopiesInRoute()
return data
}
2020-07-06 20:43:58 +02:00
// Message returns the formatted FERAG string
// for the complete route list entry
2020-05-27 21:23:36 +02:00
func (rl *RouteListEntry) Message() string {
message := rl.FeragMessage.MessageTemplate()
return message(&rl.FeragMessage, rl.Payload())
}