Class: Google

Inherits:
Openoffice show all
Defined in:
lib/roo/google.rb

Constant Summary collapse

TIMEOUT_IN_SECONDS =
2

Instance Method Summary collapse

Methods inherited from Openoffice

#as_letter, #first_column, #first_column_as_letter, #first_row_as_letter, #formula, #formula?, #last_column, #last_column_as_letter, #last_row_as_letter, letter_to_number, #number_to_letter, #officeversion, #reload, #row, #save, #set, #to_s

Constructor Details

#initialize(user, password, spreadsheetkey) ⇒ Google

Returns a new instance of Google.



92
93
94
95
96
97
98
99
100
101
# File 'lib/roo/google.rb', line 92

def initialize(user, password, spreadsheetkey)
  @cells_read = false
  @cell = Hash.new
  @cell_type = Hash.new
  Timeout.timeout(TIMEOUT_IN_SECONDS) {
    @gs = GoogleSpreadSheet.new(spreadsheetkey)
    @gs.authenticate(user, password)
    @default_sheet = nil
  }
end

Instance Method Details

#cell(row, col) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/roo/google.rb', line 116

def cell(row, col)
  row,col = normalize(row,col)
  # formula = 42 || 'sin(0.2)'

  # gs = GoogleSpreadSheet.new("ptu6bbahNZpYrdGHwteUNCw")
  # gs.authenticate('[email protected]', 'nora3033')
 # gs.add_to_cell formula
  cellname = number_to_letter(col)+row.to_s
  Timeout.timeout(TIMEOUT_IN_SECONDS) {
    return  @gs.evaluate_cell(cellname) # 'A1')
  }
end

#celltype(row, col) ⇒ Object



129
130
131
# File 'lib/roo/google.rb', line 129

def celltype(row, col)
  "string"
end

#default_sheet=(numberofsheet) ⇒ Object



112
113
114
# File 'lib/roo/google.rb', line 112

def default_sheet=(numberofsheet)
  @gs.default_sheet = numberofsheet
end

#empty?(row, col) ⇒ Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/roo/google.rb', line 133

def empty?(row, col)
  cell(row, col).empty?
end

#first_rowObject



172
173
174
175
# File 'lib/roo/google.rb', line 172

def first_row
  read_cells unless @cells_read
  1
end

#last_rowObject



177
178
179
180
# File 'lib/roo/google.rb', line 177

def last_row
  read_cells unless @cells_read
  100
end

#read_cellsObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/roo/google.rb', line 137

def read_cells
# http://spreadsheets.google.com/feeds/list/ptu6bbahNZpYrdGHwteUNCw/1/private/full
  file = File.new("/home/tp/aaa.xml")
  @doc = REXML::Document.new file
  file.close
  @doc.each_element do |element|
    if element.name == "feed"
      p "feed gefunden"
      element.each_element do |feed|
        p feed
        feed.each_element do |fe|
          p fe.name
        end
      end
    end

  end
  # @cell["1,2"] = 42
  # @cell_type["1,2"] = "string"
  # @cells_read = true
  # return

  #TODO: die Grenzen sind noch fix
  1.upto(10) do |y|
    Openoffice.letter_to_number('A').upto(Openoffice.letter_to_number('H')) do |x|
      # p x.to_s+", "+y.to_s
      # unless empty?(y,x)
      #   @cell["#{y},#{x}"] = cell(y,x)
      #   @cell_type["#{y},#{x}"] = cell(y,x)
      # end
    end
  end  
  @cells_read = true
end

#sheetsObject



103
104
105
106
107
108
109
110
# File 'lib/roo/google.rb', line 103

def sheets
# http://spreadsheets.google.com/feeds/worksheets/ptu6bbahNZpYrdGHwteUNCw/private/full
  if DateTime.now < Date.new(2007,6,15)
    return ["Sheet eins","Sheet zwei","Sheet drei"]
  else
    return []
  end
end