Added comments to Route List. Fixes #7

This commit is contained in:
Oliver Jakoubek 2020-07-06 20:43:58 +02:00
parent ad5a1ca400
commit b8b1e0ca05
2 changed files with 19 additions and 1 deletions

View file

@ -18,7 +18,7 @@ func (re *RouteEnd) SetRouteName(routeName string) {
re.routeName = routeName re.routeName = routeName
} }
// NewRouteEnd instantiates a new Route End // NewRouteEnd instantiates a new Route End
// struct and returns a pointer to it. // struct and returns a pointer to it.
func NewRouteEnd() *RouteEnd { func NewRouteEnd() *RouteEnd {
re := RouteEnd{ re := RouteEnd{

View file

@ -2,6 +2,8 @@ package feragstring
import "fmt" import "fmt"
// RouteListEntry is the struct for one route entry in the
// list of routes
type RouteListEntry struct { type RouteListEntry struct {
FeragMessage FeragMessage
routeName string routeName string
@ -10,6 +12,7 @@ type RouteListEntry struct {
copiesInRoute int copiesInRoute int
} }
// CopiesInRoute returns the formatted number of copies in the route
func (r *RouteListEntry) CopiesInRoute() string { func (r *RouteListEntry) CopiesInRoute() string {
if r.copiesInRoute == 0 { if r.copiesInRoute == 0 {
return "" return ""
@ -17,10 +20,13 @@ func (r *RouteListEntry) CopiesInRoute() string {
return fmt.Sprintf("+23%06d", r.copiesInRoute) return fmt.Sprintf("+23%06d", r.copiesInRoute)
} }
// SetCopiesInRoute set the number of copies in the route
func (r *RouteListEntry) SetCopiesInRoute(copiesInRoute int) { func (r *RouteListEntry) SetCopiesInRoute(copiesInRoute int) {
r.copiesInRoute = copiesInRoute r.copiesInRoute = copiesInRoute
} }
// RampNumber returns the formatted ramp number. Segment is
// returned only if the ramp number is set to a value.
func (r *RouteListEntry) RampNumber() string { func (r *RouteListEntry) RampNumber() string {
if r.rampNumber == -1 { if r.rampNumber == -1 {
return "" return ""
@ -28,10 +34,13 @@ func (r *RouteListEntry) RampNumber() string {
return fmt.Sprintf("+25%02d", r.rampNumber) return fmt.Sprintf("+25%02d", r.rampNumber)
} }
// SetRampNumber sets the ramp number field to an integer
// value. A value of 0 is allowed.
func (r *RouteListEntry) SetRampNumber(rampNumber int) { func (r *RouteListEntry) SetRampNumber(rampNumber int) {
r.rampNumber = rampNumber r.rampNumber = rampNumber
} }
// RouteCode returns the formatted route code.
func (r *RouteListEntry) RouteCode() string { func (r *RouteListEntry) RouteCode() string {
if r.routeCode == 0 { if r.routeCode == 0 {
return "" return ""
@ -39,18 +48,23 @@ func (r *RouteListEntry) RouteCode() string {
return fmt.Sprintf("+79%05d", r.routeCode) return fmt.Sprintf("+79%05d", r.routeCode)
} }
// SetRouteCode sets the route code field
func (r *RouteListEntry) SetRouteCode(routeCode int) { func (r *RouteListEntry) SetRouteCode(routeCode int) {
r.routeCode = routeCode r.routeCode = routeCode
} }
// RouteName returns the formatted route name.
func (r *RouteListEntry) RouteName() string { func (r *RouteListEntry) RouteName() string {
return fmt.Sprintf("+11%-13s", r.routeName) return fmt.Sprintf("+11%-13s", r.routeName)
} }
// SetRouteName sets the route name field
func (r *RouteListEntry) SetRouteName(routeName string) { func (r *RouteListEntry) SetRouteName(routeName string) {
r.routeName = routeName r.routeName = routeName
} }
// NewRouteListEntry instantiates a new Route List Entry
// struct and returns a pointer to it.
func NewRouteListEntry() *RouteListEntry { func NewRouteListEntry() *RouteListEntry {
rl := RouteListEntry{ rl := RouteListEntry{
FeragMessage: FeragMessage{ FeragMessage: FeragMessage{
@ -62,6 +76,8 @@ func NewRouteListEntry() *RouteListEntry {
return &rl return &rl
} }
// Payload returns the formatted FERAG string
// for embedding in the message
func (rl *RouteListEntry) Payload() string { func (rl *RouteListEntry) Payload() string {
data := rl.RouteName() data := rl.RouteName()
data += rl.RouteCode() data += rl.RouteCode()
@ -70,6 +86,8 @@ func (rl *RouteListEntry) Payload() string {
return data return data
} }
// Message returns the formatted FERAG string
// for the complete route list entry
func (rl *RouteListEntry) Message() string { func (rl *RouteListEntry) Message() string {
message := rl.FeragMessage.MessageTemplate() message := rl.FeragMessage.MessageTemplate()
return message(&rl.FeragMessage, rl.Payload()) return message(&rl.FeragMessage, rl.Payload())