Class: Googletastic::Table
Constant Summary
Constants included from Mixins::Namespaces
Mixins::Namespaces::NAMESPACES
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#content ⇒ Object
Returns the value of attribute content.
-
#num_rows ⇒ Object
Returns the value of attribute num_rows.
-
#spreadsheet_id ⇒ Object
Returns the value of attribute spreadsheet_id.
-
#start_row ⇒ Object
Returns the value of attribute start_row.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from Base
#acl, #attachment_path, #created_at, #etag, #head, #id, #keep_raw, #raw, #response, #synced_with, #updated_at
Attributes included from Mixins::Attributes
Class Method Summary collapse
- .build_url(options) ⇒ Object
- .client_class ⇒ Object
- .show_url(id) ⇒ Object
- .unmarshall(xml) ⇒ Object
Methods inherited from Base
Methods included from Mixins::Pagination
Methods included from Mixins::Finders
Methods included from Mixins::Parsing
Methods included from Mixins::Requesting
Methods included from Mixins::Attributes
#attribute_names, #has_attribute?, #inspect
Methods included from Mixins::Namespaces
Constructor Details
This class inherits a constructor from Googletastic::Base
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
3 4 5 |
# File 'lib/googletastic/table.rb', line 3 def columns @columns end |
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/googletastic/table.rb', line 3 def content @content end |
#num_rows ⇒ Object
Returns the value of attribute num_rows.
3 4 5 |
# File 'lib/googletastic/table.rb', line 3 def num_rows @num_rows end |
#spreadsheet_id ⇒ Object
Returns the value of attribute spreadsheet_id.
3 4 5 |
# File 'lib/googletastic/table.rb', line 3 def spreadsheet_id @spreadsheet_id end |
#start_row ⇒ Object
Returns the value of attribute start_row.
3 4 5 |
# File 'lib/googletastic/table.rb', line 3 def start_row @start_row end |
#summary ⇒ Object
Returns the value of attribute summary.
3 4 5 |
# File 'lib/googletastic/table.rb', line 3 def summary @summary end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/googletastic/table.rb', line 3 def title @title end |
Class Method Details
.build_url(options) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/googletastic/table.rb', line 16 def build_url() raise "You must specify an spreadsheet key 'key' for a table" unless [:key] [:url] ||= show_url([:key]) puts "URL: #{[:url]}" super() end |
.client_class ⇒ Object
8 9 10 |
# File 'lib/googletastic/table.rb', line 8 def client_class "Spreadsheets" end |
.show_url(id) ⇒ Object
12 13 14 |
# File 'lib/googletastic/table.rb', line 12 def show_url(id) "http://spreadsheets.google.com/feeds/#{id}/tables" end |
.unmarshall(xml) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/googletastic/table.rb', line 23 def unmarshall(xml) records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record| id = record.xpath("atom:id", ns_tag("atom")).first.text spreadsheet_id = id.gsub("http://spreadsheets.google.com/feeds/([^\/]+)/tables", "\1") id = id.gsub("http://spreadsheets.google.com/feeds/([^\/]+)/tables/([^\/]+)", "\2") title = record.xpath("atom:title", ns_tag("atom")).first.text summary = record.xpath("atom:summary", ns_tag("atom")).first.text content = record.xpath("atom:content", ns_tag("atom")).first.text data = record.xpath("gs:data", ns_tag("gs")) num_rows = data["numRows"].to_i start_row = data["startRow"].to_i columns = [] data.xpath("gs:column", ns_tag("gs")).each do |column| columns << {:name => column["name"], :index => column["index"]} end columns = columns.sort {|a,b| b["index"] <=> a["index"]}.collect{|c| c["name"]} created_at = record.xpath("atom:published", ns_tag("atom")).text updated_at = record.xpath("atom:updated", ns_tag("atom")).text Googletastic::Table.new( :id => id, :spreadsheet_id => spreadsheet_id, :title => title, :summary => summary, :content => content, :start_row => start_row, :num_rows => num_rows, :columns => columns, :updated_at => DateTime.parse(updated_at), :raw => record.to_xml ) end records end |