Class: Googletastic::Spreadsheet

Inherits:
Base
  • Object
show all
Defined in:
lib/googletastic/spreadsheet.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

Instance 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

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#edit_idObject

Returns the value of attribute edit_id.



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

def edit_id
  @edit_id
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.client_classObject



44
45
46
# File 'lib/googletastic/spreadsheet.rb', line 44

def client_class
  "Spreadsheets"
end

.index_urlObject



48
49
50
# File 'lib/googletastic/spreadsheet.rb', line 48

def index_url
  "http://spreadsheets.google.com/feeds/spreadsheets/private/full"
end

.show_url(id) ⇒ Object



52
53
54
# File 'lib/googletastic/spreadsheet.rb', line 52

def show_url(id)
  "http://spreadsheets.google.com/feeds/spreadsheets/private/full/#{id}"
end

.unmarshall(xml) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/googletastic/spreadsheet.rb', line 60

def unmarshall(xml)
  head    = unmarshall_head(xml)
  records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
    etag              = record["etag"].to_s
    id                = record.xpath("atom:id", ns_tag("atom")).first.text.gsub("http://spreadsheets.google.com/feeds/spreadsheets/", "")
    edit_id           = record.xpath("atom:link[@rel='alternate']", ns_tag("atom")).first
    edit_id           = edit_id["href"].gsub("http://spreadsheets.google.com/ccc?key=", "") if edit_id
    title             = record.xpath("atom:title", ns_tag("atom")).first.text
    content           = record.xpath("atom:content", ns_tag("atom")).first.text
    created_at        = record.xpath("atom:published", ns_tag("atom")).text
    updated_at        = record.xpath("atom:updated", ns_tag("atom")).text
    
    Googletastic::Spreadsheet.new(
      :id => id,
      :etag => etag,
      :edit_id => edit_id,
      :title => title,
      :content => content,
      :updated_at => DateTime.parse(updated_at),
      :head => head
    )
  end
  records
end

.worksheet_url(id) ⇒ Object



56
57
58
# File 'lib/googletastic/spreadsheet.rb', line 56

def worksheet_url(id)
  "http://spreadsheets.google.com/feeds/worksheets/#{id}/private/full"
end

Instance Method Details

#columnsObject



35
36
37
38
39
# File 'lib/googletastic/spreadsheet.rb', line 35

def columns
  return @columns if @columns
  row = @rows ? @rows.first : Googletastic::Row.first(:key => self.id, :worksheet_id => worksheet.id)
  @columns = row.data.keys
end

#formObject



31
32
33
# File 'lib/googletastic/spreadsheet.rb', line 31

def form
  @form ||= Googletastic::Form.find(self.id)
end

#num_rowsObject

some property on google



18
19
20
# File 'lib/googletastic/spreadsheet.rb', line 18

def num_rows
  worksheet.num_rows
end

#rowsObject



27
28
29
# File 'lib/googletastic/spreadsheet.rb', line 27

def rows
  @rows ||= Googletastic::Row.all(:key => self.id, :worksheet_id => worksheet.id)
end

#tableObject



13
14
15
# File 'lib/googletastic/spreadsheet.rb', line 13

def table
  @table ||= Googletastic::Table.first(:key => self.id)
end

#total_rowsObject

what you want



23
24
25
# File 'lib/googletastic/spreadsheet.rb', line 23

def total_rows
  @total_rows ||= Googletastic::Row.head(:key => self.id, :worksheet_id => worksheet.id).total_results
end

#worksheetObject



9
10
11
# File 'lib/googletastic/spreadsheet.rb', line 9

def worksheet
  @worksheet ||= Googletastic::Worksheet.first(:key => self.id)
end

#worksheet_urlObject



5
6
7
# File 'lib/googletastic/spreadsheet.rb', line 5

def worksheet_url
  self.class.worksheet_url(self.id)
end