penguin/golifehk

@golifehk bot in Telegram

datasources/kmb/RouteStop.go

raw ยท 1136 bytes

package kmb

import (
    query "github.com/tgckpg/golifehk/query"
)

type RouteStop struct {
    BusStop *BusStop
    RouteId string `json:"route"`
    ServiceType string `json:"service_type"`
    Direction string `json:"bound"`
    StationSeq int `json:"seq,string"`
    StationId string `json:"stop"`

    RouteStops *map[int] *RouteStop
    query.Searchable
}

type RouteStops struct {
    Type string `json:"type"`
    Version string `json:"version"`
    DateCreated string `json:"generated_timestamp"`
    RouteStops [] *RouteStop `json:"data"`
}

func ( routeStop RouteStop ) PrevStop() *RouteStop {
    if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq - 1 ]; hasKey {
        return v
    }
    return nil
}

func ( routeStop RouteStop ) NextStop() *RouteStop {
    if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq + 1 ]; hasKey {
        return v
    }
    return nil
}

type ByRouteId []RouteStop

func (a ByRouteId) Len() int           { return len(a) }
func (a ByRouteId) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByRouteId) Less(i, j int) bool { return a[i].RouteId < a[j].RouteId }