Class: Googletastic::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/googletastic/table.rb

Constant Summary

Constants included from Mixins::Namespaces

Mixins::Namespaces::NAMESPACES

Instance Attribute Summary collapse

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

#attributes

Class Method Summary collapse

Methods inherited from Base

#initialize, #to_xml

Methods included from Mixins::Pagination

included

Methods included from Mixins::Finders

included

Methods included from Mixins::Parsing

included

Methods included from Mixins::Requesting

included

Methods included from Mixins::Attributes

#attribute_names, #has_attribute?, #inspect

Methods included from Mixins::Namespaces

included

Constructor Details

This class inherits a constructor from Googletastic::Base

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



3
4
5
# File 'lib/googletastic/table.rb', line 3

def columns
  @columns
end

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/googletastic/table.rb', line 3

def content
  @content
end

#num_rowsObject

Returns the value of attribute num_rows.



3
4
5
# File 'lib/googletastic/table.rb', line 3

def num_rows
  @num_rows
end

#spreadsheet_idObject

Returns the value of attribute spreadsheet_id.



3
4
5
# File 'lib/googletastic/table.rb', line 3

def spreadsheet_id
  @spreadsheet_id
end

#start_rowObject

Returns the value of attribute start_row.



3
4
5
# File 'lib/googletastic/table.rb', line 3

def start_row
  @start_row
end

#summaryObject

Returns the value of attribute summary.



3
4
5
# File 'lib/googletastic/table.rb', line 3

def summary
  @summary
end

#titleObject

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(options)
  raise "You must specify an spreadsheet key 'key' for a table" unless options[:key]
  options[:url] ||= show_url(options[:key])
  puts "URL: #{options[:url]}"
  super(options)
end

.client_classObject



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