golifehk/datasources/mtr/bus/QueryResult.go

53 lines
1.1 KiB
Go
Raw Normal View History

2022-09-14 13:21:39 +00:00
package bus
import (
"fmt"
"strings"
)
type QueryResult struct {
Schedules *map[BusStop] *BusStopBuses
Lang string
Error error
}
func ( result QueryResult ) Message() string {
if result.Error != nil {
return fmt.Sprintf( "%s", result.Error )
}
sb := strings.Builder{}
for busStop, buses := range *result.Schedules {
if busStop.PrevStop() != nil {
sb.WriteString( (*busStop.PrevStop().Name)[ result.Lang ] )
sb.WriteString( " > *" )
}
sb.WriteString( (*busStop.Name)[ result.Lang ] )
sb.WriteString( "*" )
if busStop.NextStop() != nil {
sb.WriteString( " > " )
sb.WriteString( (*busStop.NextStop().Name)[ result.Lang ] )
}
sb.WriteString( "\n" )
for _, bus := range buses.Buses {
sb.WriteString( " * " )
2022-09-14 14:54:51 +00:00
if bus.ETAText == "" {
sb.WriteString( bus.ETDText )
} else {
sb.WriteString( bus.ETAText )
}
2022-09-14 13:21:39 +00:00
sb.WriteString( "\n" )
}
sb.WriteString( "\n" )
}
return sb.String()
}