UNPKG

node-511

Version:

Lightweight node.js wrapper for the 511.org real time driving times and transit departure APIs

87 lines (77 loc) 4.55 kB
// Generated by CoffeeScript 1.7.1 (function() { var AbstractService, GetNextDeparturesByStopName, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; AbstractService = require('./AbstractService'); GetNextDeparturesByStopName = (function(_super) { __extends(GetNextDeparturesByStopName, _super); function GetNextDeparturesByStopName() { this.invoke = __bind(this.invoke, this); return GetNextDeparturesByStopName.__super__.constructor.apply(this, arguments); } GetNextDeparturesByStopName.prototype.invoke = function(parameters, callback) { if (parameters == null) { parameters = {}; } if (callback == null) { callback = function() {}; } if (!parameters.agencyName) { return callback(new Error("Call to service " + this.constructor.name + " must include parameter agencyName")); } if (!parameters.stopName) { return callback(new Error("Call to service " + this.constructor.name + " must include parameter stopName")); } return GetNextDeparturesByStopName.__super__.invoke.call(this, parameters, callback); }; GetNextDeparturesByStopName.prototype._parse = function(obj) { var agency, departureTimes, name, routes, stops, _A, _DT, _R, _S, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref2, _ref20, _ref21, _ref22, _ref23, _ref24, _ref25, _ref26, _ref27, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9; _ref4 = (_ref = obj != null ? (_ref1 = obj.RTT) != null ? (_ref2 = _ref1.AgencyList) != null ? (_ref3 = _ref2[0]) != null ? _ref3.Agency : void 0 : void 0 : void 0 : void 0) != null ? _ref : []; for (_i = 0, _len = _ref4.length; _i < _len; _i++) { _A = _ref4[_i]; if ((_A != null ? (_ref5 = _A['$']) != null ? _ref5.Name : void 0 : void 0)) { name = _A != null ? (_ref6 = _A['$']) != null ? _ref6.Name : void 0 : void 0; agency = { HasDirection: 'True' === (_A != null ? (_ref7 = _A['$']) != null ? _ref7.HasDirection : void 0 : void 0), Mode: (_ref8 = _A != null ? (_ref9 = _A['$']) != null ? _ref9.Mode : void 0 : void 0) != null ? _ref8 : null }; routes = {}; _ref13 = (_ref10 = _A != null ? (_ref11 = _A.RouteList) != null ? (_ref12 = _ref11[0]) != null ? _ref12.Route : void 0 : void 0 : void 0) != null ? _ref10 : []; for (_j = 0, _len1 = _ref13.length; _j < _len1; _j++) { _R = _ref13[_j]; if ((_R != null ? (_ref14 = _R['$']) != null ? _ref14.Name : void 0 : void 0)) { routes[_R['$'].Name] = { Code: (_ref15 = _R != null ? (_ref16 = _R['$']) != null ? _ref16.Code : void 0 : void 0) != null ? _ref15 : null }; } stops = []; _ref20 = (_ref17 = _R != null ? (_ref18 = _R.StopList) != null ? (_ref19 = _ref18[0]) != null ? _ref19.Stop : void 0 : void 0 : void 0) != null ? _ref17 : []; for (_k = 0, _len2 = _ref20.length; _k < _len2; _k++) { _S = _ref20[_k]; if (((_ref21 = _S['$']) != null ? _ref21.name : void 0)) { departureTimes = []; _ref25 = (_ref22 = _S != null ? (_ref23 = _S.DepartureTimeList) != null ? (_ref24 = _ref23[0]) != null ? _ref24.DepartureTime : void 0 : void 0 : void 0) != null ? _ref22 : []; for (_l = 0, _len3 = _ref25.length; _l < _len3; _l++) { _DT = _ref25[_l]; departureTimes.push(_DT); } stops.push({ Name: _S['$'].name, StopCode: (_ref26 = _S != null ? (_ref27 = _S['$']) != null ? _ref27.StopCode : void 0 : void 0) != null ? _ref26 : null, DepartureTimes: departureTimes }); } } routes[_R['$'].Name].Stops = stops; } agency.Routes = routes; } } return agency; }; return GetNextDeparturesByStopName; })(AbstractService); module.exports = GetNextDeparturesByStopName; }).call(this);