53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
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( " * " )
|
|
if bus.ETAText == "" {
|
|
sb.WriteString( bus.ETDText )
|
|
} else {
|
|
sb.WriteString( bus.ETAText )
|
|
}
|
|
sb.WriteString( "\n" )
|
|
}
|
|
|
|
sb.WriteString( "\n" )
|
|
}
|
|
|
|
return sb.String()
|
|
}
|