Class: GoogleSpreadsheet::Spreadsheet
- Inherits:
-
Object
- Object
- GoogleSpreadsheet::Spreadsheet
- Includes:
- Util
- Defined in:
- lib/google_spreadsheet.rb
Overview
Use methods in GoogleSpreadsheet::Session to get GoogleSpreadsheet::Spreadsheet object.
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Title of the spreadsheet.
-
#worksheets_feed_url ⇒ Object
readonly
URL of worksheet-based feed of the spreadsheet.
Instance Method Summary collapse
-
#add_worksheet(title, max_rows = 100, max_cols = 20) ⇒ Object
Adds a new worksheet to the spreadsheet.
-
#initialize(session, worksheets_feed_url, title = nil) ⇒ Spreadsheet
constructor
:nodoc:.
-
#key ⇒ Object
Key of the spreadsheet.
-
#tables ⇒ Object
Returns list of tables in the spreadsheet.
-
#tables_feed_url ⇒ Object
Tables feed URL of the spreadsheet.
-
#worksheets ⇒ Object
Returns worksheets of the spreadsheet as array of GoogleSpreadsheet::Worksheet.
Methods included from Util
as_utf8, encode_query, h, http_request, uri_encode
Constructor Details
#initialize(session, worksheets_feed_url, title = nil) ⇒ Spreadsheet
:nodoc:
275 276 277 278 279 |
# File 'lib/google_spreadsheet.rb', line 275 def initialize(session, worksheets_feed_url, title = nil) #:nodoc: @session = session @worksheets_feed_url = worksheets_feed_url @title = title end |
Instance Attribute Details
#title ⇒ Object (readonly)
Title of the spreadsheet. So far only available if you get this object by GoogleSpreadsheet::Session#spreadsheets.
286 287 288 |
# File 'lib/google_spreadsheet.rb', line 286 def title @title end |
#worksheets_feed_url ⇒ Object (readonly)
URL of worksheet-based feed of the spreadsheet.
282 283 284 |
# File 'lib/google_spreadsheet.rb', line 282 def worksheets_feed_url @worksheets_feed_url end |
Instance Method Details
#add_worksheet(title, max_rows = 100, max_cols = 20) ⇒ Object
Adds a new worksheet to the spreadsheet. Returns added GoogleSpreadsheet::Worksheet.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/google_spreadsheet.rb', line 317 def add_worksheet(title, max_rows = 100, max_cols = 20) xml = " <entry xmlns='http://www.w3.org/2005/Atom'\n xmlns:gs='http://schemas.google.com/spreadsheets/2006'>\n <title>\#{h(title)}</title>\n <gs:rowCount>\#{h(max_rows)}</gs:rowCount>\n <gs:colCount>\#{h(max_cols)}</gs:colCount>\n </entry>\n EOS\n doc = @session.post(@worksheets_feed_url, xml)\n url = as_utf8(doc.search(\n \"link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']\")[0][\"href\"])\n return Worksheet.new(@session, self, url, title)\nend\n" |
#key ⇒ Object
Key of the spreadsheet.
289 290 291 292 293 294 295 296 |
# File 'lib/google_spreadsheet.rb', line 289 def key if !(@worksheets_feed_url =~ %r{http://spreadsheets.google.com/feeds/worksheets/(.*)/private/full}) raise(GoogleSpreadsheet::Error, "worksheets feed URL is in unknown format: #{@worksheets_feed_url}") end return $1 end |
#tables ⇒ Object
Returns list of tables in the spreadsheet.
333 334 335 336 |
# File 'lib/google_spreadsheet.rb', line 333 def tables doc = @session.get(self.tables_feed_url) return doc.search("entry").map(){ |e| Table.new(@session, e) }.freeze() end |
#tables_feed_url ⇒ Object
Tables feed URL of the spreadsheet.
299 300 301 |
# File 'lib/google_spreadsheet.rb', line 299 def tables_feed_url return "http://spreadsheets.google.com/feeds/#{self.key}/tables" end |
#worksheets ⇒ Object
Returns worksheets of the spreadsheet as array of GoogleSpreadsheet::Worksheet.
304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/google_spreadsheet.rb', line 304 def worksheets doc = @session.get(@worksheets_feed_url) result = [] for entry in doc.search("entry") title = as_utf8(entry.search("title").text) url = as_utf8(entry.search( "link[@rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"]) result.push(Worksheet.new(@session, self, url, title)) end return result.freeze() end |