Skip to content

Instantly share code, notes, and snippets.

@nekman
Created February 3, 2014 00:10
Show Gist options
  • Save nekman/8777046 to your computer and use it in GitHub Desktop.
Save nekman/8777046 to your computer and use it in GitHub Desktop.
define([
'backbone',
'lodash'
],
function(Backbone, _) {
'use strict';
/**
* Sheet Model
*/
return Backbone.Model.extend({
initialize: function(settings) {
this.key = settings.key;
this.name = settings.name;
this.pollintervall = settings.poll || 1;
},
parse: function(res) {
var sheet = {};
_.each(res.feed.entry, function(entry) {
// entry.title.$t = A1, B2, etc.
var colName = entry.title.$t[0], //A
rowNum = entry.title.$t[1]; //1
if (!sheet[rowNum]) {
sheet[rowNum] = [];
}
sheet[rowNum].push({
column: colName,
value: entry.content.$t
});
});
// from: { row1: [cells1], rowN: [cellsN] }
// to: [ [cells1], [cellsN] ]
this.sheet = _.map(sheet, function(cells) {
return cells;
});
return this;
},
url: function() {
return 'https://spreadsheets.google.com/feeds/cells/{key}/od6/public/basic?alt=json'
.replace(/{key}/, this.key);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment