Example #1
0
func createFareRule(r map[string]string, fareattributes map[string]*gtfs.FareAttribute, routes map[string]*gtfs.Route) {
	var fareattr *gtfs.FareAttribute
	var fareid string

	fareid = getString("fare_id", r, true)

	// first, check if the service already exists
	if val, ok := fareattributes[fareid]; ok {
		fareattr = val
	} else {
		panic(fmt.Sprintf("No fare attribute with id %s found", fareid))
	}

	// create fare attribute
	rule := new(gtfs.FareAttributeRule)

	var route_id string
	route_id = getString("route_id", r, false)

	if len(route_id) > 0 {
		if val, ok := routes[route_id]; ok {
			rule.Route = val
		} else {
			panic(fmt.Sprintf("No route with id %s found", route_id))
		}
	}

	rule.Origin_id = getString("origin_id", r, false)
	rule.Destination_id = getString("destination_id", r, false)
	rule.Contains_id = getString("contains_id", r, false)

	fareattr.Rules = append(fareattr.Rules, rule)
}
Example #2
0
func createFareAttribute(r map[string]string) *gtfs.FareAttribute {
	a := new(gtfs.FareAttribute)

	a.Id = getString("fare_id", r, true)
	a.Price = getString("price", r, false)
	a.Currency_type = getString("currency_type", r, true)
	a.Payment_method = getInt("payment_method", r, false)
	a.Transfers = getInt("transfers", r, true)
	a.Transfer_duration = getInt("transfer_duration", r, false)

	return a
}