Class: Googletastic::Worksheet

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

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#num_columnsObject

Returns the value of attribute num_columns.



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

def num_columns
  @num_columns
end

#num_rowsObject

Returns the value of attribute num_rows.



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

def num_rows
  @num_rows
end

#spreadsheet_idObject

Returns the value of attribute spreadsheet_id.



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

def spreadsheet_id
  @spreadsheet_id
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.build_url(options) ⇒ Object



16
17
18
19
20
# File 'lib/googletastic/worksheet.rb', line 16

def build_url(options)
  raise "You must specify an spreadsheet key 'key' for a worksheet" unless options[:key]
  options[:url] ||= show_url(options[:key])
  super(options)
end

.client_classObject



8
9
10
# File 'lib/googletastic/worksheet.rb', line 8

def client_class
  "Spreadsheets"
end

.show_url(id) ⇒ Object



12
13
14
# File 'lib/googletastic/worksheet.rb', line 12

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

.unmarshall(xml) ⇒ Object



22
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
# File 'lib/googletastic/worksheet.rb', line 22

def unmarshall(xml)
  head    = unmarshall_head(xml)
  records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
    id                = record.xpath("atom:id", ns_tag("atom")).first.text
    ids               = id =~ /http:\/\/spreadsheets\.google\.com\/feeds\/worksheets\/([^\/]+)\/([^\/]+)/
    spreadsheet_id    = $1
    id                = $2
    title             = record.xpath("atom:title", ns_tag("atom")).first.text
    content           = record.xpath("atom:content", ns_tag("atom")).first.text
    updated_at        = record.xpath("atom:updated", ns_tag("atom")).text
    num_rows          = record.xpath("gs:rowCount", ns_tag("gs")).text.to_i
    num_columns       = record.xpath("gs:colCount", ns_tag("gs")).text.to_i
    
    worksheet = Googletastic::Worksheet.new(
      :id => id,
      :spreadsheet_id => spreadsheet_id,
      :title => title,
      :content => content,
      :num_rows => num_rows,
      :num_columns => num_columns,
      :updated_at => DateTime.parse(updated_at),
      :head => head
    )

    worksheet
  end
  records
end