class GoogleSpreadsheet::List

Provides access to cells using column names. Use GoogleSpreadsheet::Worksheet#list to get GoogleSpreadsheet::List object.

Public Instance Methods

[](index) click to toggle source

Returns Hash-like object (GoogleSpreadsheet::ListRow) for the row with the index. Keys of the object are colum names (the first row). The second row has index 0.

Note that updates to the returned object are not sent to the server until you call GoogleSpreadsheet::Worksheet#save.

# File lib/google_spreadsheet/list.rb, line 36
def [](index)
  return ListRow.new(self, index)
end
[]=(index, hash) click to toggle source

Updates the row with the index with the given Hash object. Keys of hash are colum names (the first row). The second row has index 0.

Note that update is not sent to the server until you call GoogleSpreadsheet::Worksheet#save.

# File lib/google_spreadsheet/list.rb, line 46
def []=(index, hash)
  self[index].replace(hash)
end
each() { |self| ... } click to toggle source

Iterates over Hash-like object (GoogleSpreadsheet::ListRow) for each row (except for the first row). Keys of the object are colum names (the first row).

# File lib/google_spreadsheet/list.rb, line 53
def each(&block)
  for i in 0...self.size
    yield(self[i])
  end
end
keys() click to toggle source

Column names i.e. the contents of the first row. Duplicates are removed.

# File lib/google_spreadsheet/list.rb, line 61
def keys
  return (1..@worksheet.num_cols).map(){ |i| @worksheet[1, i] }.uniq()
end
keys=(ary) click to toggle source

Updates column names i.e. the contents of the first row.

Note that update is not sent to the server until you call GoogleSpreadsheet::Worksheet#save.

# File lib/google_spreadsheet/list.rb, line 69
def keys=(ary)
  for i in 1..ary.size
    @worksheet[1, i] = ary[i - 1]
  end
  for i in (ary.size + 1)..@worksheet.num_cols
    @worksheet[1, i] = ""
  end
end
push(hash) click to toggle source

Adds a new row to the bottom. Keys of hash are colum names (the first row). Returns GoogleSpreadsheet::ListRow for the new row.

Note that update is not sent to the server until you call GoogleSpreadsheet::Worksheet#save.

# File lib/google_spreadsheet/list.rb, line 84
def push(hash)
  row = self[self.size]
  row.update(hash)
  return row
end
size() click to toggle source

Number of non-empty rows in the worksheet excluding the first row.

# File lib/google_spreadsheet/list.rb, line 26
def size
  return @worksheet.num_rows - 1
end
to_hash_array() click to toggle source

Returns all rows (except for the first row) as Array of Hash. Keys of Hash objects are colum names (the first row).

# File lib/google_spreadsheet/list.rb, line 92
def to_hash_array()
  return self.map(){ |r| r.to_hash() }
end