Class: GoogleSpreadsheet::Table

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/google_spreadsheet.rb

Overview

Use GoogleSpreadsheet::Worksheet#add_table to create table. Use GoogleSpreadsheet::Worksheet#tables to get GoogleSpreadsheet::Table objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

as_utf8, encode_query, h

Constructor Details

#initialize(session, entry) ⇒ Table

:nodoc:



455
456
457
458
459
460
# File 'lib/google_spreadsheet.rb', line 455

def initialize(session, entry) #:nodoc:
  @columns = {}
  @worksheet_title = as_utf8(entry.search("gs:worksheet")[0]["name"])
  @records_url = as_utf8(entry.search("content")[0]["src"])
  @session = session
end

Instance Attribute Details

#worksheet_titleObject (readonly)

Title of the worksheet the table belongs to.



463
464
465
# File 'lib/google_spreadsheet.rb', line 463

def worksheet_title
  @worksheet_title
end

Instance Method Details

#add_record(values) ⇒ Object

Adds a record.



466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/google_spreadsheet.rb', line 466

def add_record(values)
  fields = ""
  values.each do |name, value|
    fields += "<gs:field name='#{h(name)}'>#{h(value)}</gs:field>"
  end
  xml ="    <entry\n        xmlns=\"http://www.w3.org/2005/Atom\"\n        xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\">\n      \#{fields}\n    </entry>\n  EOS\n  @session.request(:post, @records_url, :data => xml)\nend\n"

#recordsObject

Returns records in the table.



482
483
484
485
# File 'lib/google_spreadsheet.rb', line 482

def records
  doc = @session.request(:get, @records_url)
  return doc.search("entry").map(){ |e| Record.new(@session, e) }
end