Skip to content

Instantly share code, notes, and snippets.

@fsrc
Created September 26, 2012 22:49
Show Gist options
  • Save fsrc/3791140 to your computer and use it in GitHub Desktop.
Save fsrc/3791140 to your computer and use it in GitHub Desktop.
CoffeeScript wrap up values within function objects? Kind of currying?
class SimpleSheet
# Returns object where each property
# represent the index in the array
@indices: (columnNames) ->
result = {}
result[name] = i for i, name of columnNames
result
constructor: (@gsheet) ->
range = @gsheet.getDataRange()
table = range.getValues()
# Pass table 0th row to indices fn and remove that
# row from table array.
indices = SimpleSheet.indices table.shift()
@rowForIndex = do (table) -> (index) ->
table[index]
@valueForColumn = do (indices) -> (row, column) ->
row[indices[column]]
sheet = new SimpleSheet(dataSheet)
row = sheet.rowForIndex 3
value = row.valueForColumn 'InvoiceNumber'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment