PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/app/scripts/collections/prediction-collection.js

https://github.com/davidchchang/mystops
JavaScript | 31 lines | 23 code | 7 blank | 1 comment | 1 complexity | f6f56bbe0f4c9db44bed4464ccd56e04 MD5 | raw file
  1. /*global mystops, Backbone*/
  2. mystops.Collections.PredictionCollection = Backbone.Collection.extend({
  3. model: mystops.Models.PredictionModel,
  4. url: 'http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=ttc',
  5. comparator: function (model) {
  6. return +model.get('minutes');
  7. },
  8. parse: function (data) {
  9. var parsed = [];
  10. $(data).find('direction').each(function (index) {
  11. var dataDir = $(this).attr('title');
  12. $(this).find('prediction').each(function (index) {
  13. var dataMins = $(this).attr('minutes');
  14. parsed.push({minutes: dataMins, direction: dataDir});
  15. });
  16. });
  17. return parsed;
  18. },
  19. fetch: function (options) {
  20. options = options || {};
  21. options.dataType = "xml";
  22. Backbone.Collection.prototype.fetch.call(this, options);
  23. }
  24. });