Class: GData::Spreadsheet

Inherits:
Base
  • Object
show all
Defined in:
lib/roo/google.rb

Instance Method Summary collapse

Instance Method Details

#add_to_cell_roo(row, col, value, sheet_no = 1) ⇒ Object

– new @@ added sheet_no to definition



66
67
68
# File 'lib/roo/google.rb', line 66

def add_to_cell_roo(row,col,value, sheet_no=1)
  save_entry_roo(entry_roo(value,row,col), sheet_no)
end

#entry_roo(formula, row = 1, col = 1) ⇒ Object

– new



56
57
58
59
60
61
62
# File 'lib/roo/google.rb', line 56

def entry_roo(formula, row=1, col=1)
<<-XML
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
  <gs:cell row='#{row}' col='#{col}' inputValue='#{formula}' />
</entry>
XML
end

#evaluate_cell(cell, sheet_no = 1) ⇒ Object

– modified

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
# File 'lib/roo/google.rb', line 21

def evaluate_cell(cell, sheet_no=1)
  raise ArgumentError, "invalid cell: #{cell}" unless cell
  raise ArgumentError, "invalid sheet_no: #{sheet_no}" unless sheet_no >0 and sheet_no.class == Fixnum
  path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}/#{cell}"
  doc = Hpricot(request(path))
  result = (doc/"content").inner_html
end

#fulldoc(sheet_no) ⇒ Object



89
90
91
92
93
# File 'lib/roo/google.rb', line 89

def fulldoc(sheet_no)
  path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}"
  doc = Hpricot(request(path))
  return doc
end

#get_one_sheetObject

– new



71
72
73
74
# File 'lib/roo/google.rb', line 71

def get_one_sheet
  path = "/feeds/cells/#{@spreadsheet_id}/1/#{visibility}/#{projection}"
  doc = Hpricot(request(path))
end

new



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/roo/google.rb', line 77

def oben_unten_links_rechts(sheet_no)
  path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}"
  doc = Hpricot(request(path))
  rows = []
  cols = []
  (doc/"gs:cell").each {|item|
    rows.push item['row'].to_i
    cols.push item['col'].to_i
  }
  return rows.min, rows.max, cols.min, cols.max
end

#projectionObject



16
17
18
# File 'lib/roo/google.rb', line 16

def projection
  @headers ? "full" : "values"
end

#save_entry_roo(entry, sheet_no) ⇒ Object

– new @@ added sheet_no to definition

Raises:



49
50
51
52
53
# File 'lib/roo/google.rb', line 49

def save_entry_roo(entry, sheet_no)
  raise GoogleWriteError, "unable to write to public spreadsheets" if visibility == 'public'
  path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}"
  post(path, entry)
end

#sheetlistObject

– new



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/roo/google.rb', line 30

def sheetlist
  path = "/feeds/worksheets/#{@spreadsheet_id}/#{visibility}/#{projection}"
  doc = Hpricot(request(path))
  result = []
  (doc/"content").each { |elem|
    result << elem.inner_html
  }
  if result.size == 0 
    if (doc/"h2").inner_html =~ /Error/
      raise GoogleHTTPError, "#{(doc/'h2').inner_html}: #{(doc/'title').inner_html} [key '#{@spreadsheet_id}']"
    else
      raise GoogleReadError, "#{doc} [key '#{@spreadsheet_id}']"
    end  
  end
  result
end

#visibilityObject



12
13
14
# File 'lib/roo/google.rb', line 12

def visibility
  @headers ? "private" : "public"
end