google_drive 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -116,11 +116,39 @@ module GoogleDrive
|
|
116
116
|
return files_with_type("folder", params)
|
117
117
|
end
|
118
118
|
|
119
|
+
# Returns a file (can be a spreadsheet, document, subcollection or other files) in the
|
120
|
+
# collection which exactly matches +title+ as GoogleDrive::File.
|
121
|
+
# Returns nil if not found. If multiple collections with the +title+ are found, returns
|
122
|
+
# one of them.
|
123
|
+
#
|
124
|
+
# If given an Array, does a recursive subcollection traversal.
|
125
|
+
def file_by_title(title)
|
126
|
+
return file_by_title_with_type(title, nil)
|
127
|
+
end
|
128
|
+
|
119
129
|
# Returns its subcollection whose title exactly matches +title+ as GoogleDrive::Collection.
|
120
130
|
# Returns nil if not found. If multiple collections with the +title+ are found, returns
|
121
131
|
# one of them.
|
132
|
+
#
|
133
|
+
# If given an Array, does a recursive subcollection traversal.
|
122
134
|
def subcollection_by_title(title)
|
123
|
-
return
|
135
|
+
return file_by_title_with_type(title, "folder")
|
136
|
+
end
|
137
|
+
|
138
|
+
protected
|
139
|
+
|
140
|
+
def file_by_title_with_type(title, type)
|
141
|
+
if title.is_a?(Array)
|
142
|
+
rel_path = title
|
143
|
+
if rel_path.empty?
|
144
|
+
return self
|
145
|
+
else
|
146
|
+
parent = subcollection_by_title(rel_path[0...-1])
|
147
|
+
return parent && parent.file_by_title_with_type(rel_path[-1], type)
|
148
|
+
end
|
149
|
+
else
|
150
|
+
return files_with_type(type, "title" => title, "title-exact" => "true")[0]
|
151
|
+
end
|
124
152
|
end
|
125
153
|
|
126
154
|
private
|
data/lib/google_drive/session.rb
CHANGED
@@ -132,8 +132,15 @@ module GoogleDrive
|
|
132
132
|
# Returns GoogleDrive::File or its subclass whose title exactly matches +title+.
|
133
133
|
# Returns nil if not found. If multiple files with the +title+ are found, returns
|
134
134
|
# one of them.
|
135
|
+
#
|
136
|
+
# If given an Array, traverses collections by title. e.g.
|
137
|
+
# session.file_by_title(["myfolder", "mysubfolder/even/w/slash", "myfile"])
|
135
138
|
def file_by_title(title)
|
136
|
-
|
139
|
+
if title.is_a?(Array)
|
140
|
+
return self.root_collection.file_by_title(title)
|
141
|
+
else
|
142
|
+
return files("title" => title, "title-exact" => "true")[0]
|
143
|
+
end
|
137
144
|
end
|
138
145
|
|
139
146
|
# Returns list of spreadsheets for the user as array of GoogleDrive::Spreadsheet.
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# Author: Hiroshi Ichikawa <http://gimite.net/>
|
2
2
|
# The license of this source is "New BSD Licence"
|
3
3
|
|
4
|
+
require "time"
|
5
|
+
|
4
6
|
require "google_drive/util"
|
5
7
|
require "google_drive/error"
|
6
8
|
require "google_drive/worksheet"
|
@@ -173,9 +175,10 @@ module GoogleDrive
|
|
173
175
|
result = []
|
174
176
|
doc.css("entry").each() do |entry|
|
175
177
|
title = entry.css("title").text
|
178
|
+
updated = Time.parse(entry.css("updated").text)
|
176
179
|
url = entry.css(
|
177
180
|
"link[rel='http://schemas.google.com/spreadsheets/2006#cellsfeed']")[0]["href"]
|
178
|
-
result.push(Worksheet.new(@session, self, url, title))
|
181
|
+
result.push(Worksheet.new(@session, self, url, title, updated))
|
179
182
|
end
|
180
183
|
return result.freeze()
|
181
184
|
end
|
@@ -17,12 +17,13 @@ module GoogleDrive
|
|
17
17
|
|
18
18
|
include(Util)
|
19
19
|
|
20
|
-
def initialize(session, spreadsheet, cells_feed_url, title = nil) #:nodoc:
|
20
|
+
def initialize(session, spreadsheet, cells_feed_url, title = nil, updated = nil) #:nodoc:
|
21
21
|
|
22
22
|
@session = session
|
23
23
|
@spreadsheet = spreadsheet
|
24
24
|
@cells_feed_url = cells_feed_url
|
25
25
|
@title = title
|
26
|
+
@updated = updated
|
26
27
|
|
27
28
|
@cells = nil
|
28
29
|
@input_values = nil
|
@@ -91,6 +92,13 @@ module GoogleDrive
|
|
91
92
|
@modified.add([row, col])
|
92
93
|
self.max_rows = row if row > @max_rows
|
93
94
|
self.max_cols = col if col > @max_cols
|
95
|
+
if value.empty?
|
96
|
+
@num_rows = nil
|
97
|
+
@num_cols = nil
|
98
|
+
else
|
99
|
+
@num_rows = row if row > num_rows
|
100
|
+
@num_cols = col if col > num_cols
|
101
|
+
end
|
94
102
|
end
|
95
103
|
|
96
104
|
# Updates cells in a rectangle area by a two-dimensional Array.
|
@@ -140,13 +148,17 @@ module GoogleDrive
|
|
140
148
|
# Row number of the bottom-most non-empty row.
|
141
149
|
def num_rows
|
142
150
|
reload() if !@cells
|
143
|
-
|
151
|
+
# Memoizes it because this can be bottle-neck.
|
152
|
+
# https://github.com/gimite/google-drive-ruby/pull/49
|
153
|
+
return @num_rows ||= @input_values.select(){ |(r, c), v| !v.empty? }.map(){ |(r, c), v| r }.max || 0
|
144
154
|
end
|
145
155
|
|
146
156
|
# Column number of the right-most non-empty column.
|
147
157
|
def num_cols
|
148
158
|
reload() if !@cells
|
149
|
-
|
159
|
+
# Memoizes it because this can be bottle-neck.
|
160
|
+
# https://github.com/gimite/google-drive-ruby/pull/49
|
161
|
+
return @num_cols ||= @input_values.select(){ |(r, c), v| !v.empty? }.map(){ |(r, c), v| c }.max || 0
|
150
162
|
end
|
151
163
|
|
152
164
|
# Number of rows including empty rows.
|
@@ -183,6 +195,12 @@ module GoogleDrive
|
|
183
195
|
return @title
|
184
196
|
end
|
185
197
|
|
198
|
+
# Date updated of the worksheet (shown as tab label in Web interface).
|
199
|
+
def updated
|
200
|
+
reload() if !@updated
|
201
|
+
return @updated
|
202
|
+
end
|
203
|
+
|
186
204
|
# Updates title of the worksheet.
|
187
205
|
# Note that update is not sent to the server until you call save().
|
188
206
|
def title=(title)
|
@@ -217,6 +235,9 @@ module GoogleDrive
|
|
217
235
|
@max_cols = doc.css("gs|colCount").text.to_i()
|
218
236
|
@title = doc.css("feed > title")[0].text
|
219
237
|
|
238
|
+
@num_cols = nil
|
239
|
+
@num_rows = nil
|
240
|
+
|
220
241
|
@cells = {}
|
221
242
|
@input_values = {}
|
222
243
|
@numeric_values = {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_drive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|