hmcgowan-roo 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/roo/excelx.rb +0 -1
- data/lib/roo/google.rb +48 -68
- data/lib/roo/version.rb +1 -1
- metadata +2 -2
data/lib/roo/excelx.rb
CHANGED
data/lib/roo/google.rb
CHANGED
@@ -73,12 +73,6 @@ XML
|
|
73
73
|
return doc
|
74
74
|
end
|
75
75
|
|
76
|
-
def celldoc(sheet_no, cell_name)
|
77
|
-
path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/private/full" + cell_name
|
78
|
-
doc = Hpricot(request(path))
|
79
|
-
return doc
|
80
|
-
end
|
81
|
-
|
82
76
|
end # class
|
83
77
|
end # module
|
84
78
|
|
@@ -98,9 +92,8 @@ class Google < GenericSpreadsheet
|
|
98
92
|
password = ENV['GOOGLE_PASSWORD']
|
99
93
|
end
|
100
94
|
@default_sheet = nil
|
101
|
-
@cell = Hash.new
|
102
|
-
@
|
103
|
-
@cell_type = Hash.new
|
95
|
+
@cell = Hash.new {|h,k| h[k]=Hash.new}
|
96
|
+
@cell_type = Hash.new {|h,k| h[k]=Hash.new}
|
104
97
|
@formula = Hash.new
|
105
98
|
@first_row = Hash.new
|
106
99
|
@last_row = Hash.new
|
@@ -113,6 +106,7 @@ class Google < GenericSpreadsheet
|
|
113
106
|
@time_format = '%H:%M:%S'
|
114
107
|
@gs = GData::Spreadsheet.new(spreadsheetkey)
|
115
108
|
@gs.authenticate(user, password)
|
109
|
+
@sheetlist = @gs.sheetlist
|
116
110
|
#-- ----------------------------------------------------------------------
|
117
111
|
#-- TODO: Behandlung von Berechtigungen hier noch einbauen ???
|
118
112
|
#-- ----------------------------------------------------------------------
|
@@ -124,12 +118,10 @@ class Google < GenericSpreadsheet
|
|
124
118
|
|
125
119
|
# returns an array of sheet names in the spreadsheet
|
126
120
|
def sheets
|
127
|
-
|
121
|
+
@sheetlist
|
128
122
|
end
|
129
123
|
|
130
124
|
def date?(string)
|
131
|
-
return false if string.class == Float
|
132
|
-
return true if string.class == Date
|
133
125
|
begin
|
134
126
|
Date.strptime(string, @date_format)
|
135
127
|
true
|
@@ -140,8 +132,6 @@ class Google < GenericSpreadsheet
|
|
140
132
|
|
141
133
|
# is String a time with format HH:MM:SS?
|
142
134
|
def time?(string)
|
143
|
-
return false if string.class == Float
|
144
|
-
return true if string.class == Date
|
145
135
|
begin
|
146
136
|
DateTime.strptime(string, @time_format)
|
147
137
|
true
|
@@ -151,8 +141,6 @@ class Google < GenericSpreadsheet
|
|
151
141
|
end
|
152
142
|
|
153
143
|
def datetime?(string)
|
154
|
-
return false if string.class == Float
|
155
|
-
return true if string.class == Date
|
156
144
|
begin
|
157
145
|
DateTime.strptime(string, @datetime_format)
|
158
146
|
true
|
@@ -161,6 +149,10 @@ class Google < GenericSpreadsheet
|
|
161
149
|
end
|
162
150
|
end
|
163
151
|
|
152
|
+
def numeric?(string)
|
153
|
+
string =~ /^[0-9]+[\.]*[0-9]*$/
|
154
|
+
end
|
155
|
+
|
164
156
|
def timestring_to_seconds(value)
|
165
157
|
hms = value.split(':')
|
166
158
|
hms[0].to_i*3600 + hms[1].to_i*60 + hms[2].to_i
|
@@ -313,9 +305,11 @@ class Google < GenericSpreadsheet
|
|
313
305
|
row,col = normalize(row,col)
|
314
306
|
@gs.add_to_cell_roo(row,col,value,sheet_no)
|
315
307
|
# re-read the portion of the document that has changed
|
316
|
-
if @cells_read[sheet]
|
317
|
-
|
318
|
-
|
308
|
+
if @cells_read[sheet]
|
309
|
+
key = "#{row},#{col}"
|
310
|
+
(value, value_type) = determine_datatype(value.to_s)
|
311
|
+
@cell[sheet][key] = value
|
312
|
+
@cell_type[sheet][key] = value_type
|
319
313
|
end
|
320
314
|
end
|
321
315
|
|
@@ -361,74 +355,60 @@ class Google < GenericSpreadsheet
|
|
361
355
|
|
362
356
|
private
|
363
357
|
|
364
|
-
# read all cells in a sheet.
|
365
|
-
|
366
|
-
def read_cells(sheet=nil, cell_name=nil)
|
358
|
+
# read all cells in a sheet.
|
359
|
+
def read_cells(sheet=nil)
|
367
360
|
sheet = @default_sheet unless sheet
|
368
361
|
raise RangeError, "illegal sheet <#{sheet}>" unless sheets.index(sheet)
|
369
362
|
sheet_no = sheets.index(sheet)+1
|
370
|
-
|
371
|
-
xml = cell_name ? @gs.celldoc(sheet_no, cell_name).to_s : @gs.fulldoc(sheet_no).to_s
|
363
|
+
xml = @gs.fulldoc(sheet_no).to_s
|
372
364
|
doc = XML::Parser.string(xml).parse
|
373
365
|
doc.find("//*[local-name()='entry']").each do |entry|
|
374
366
|
key = nil;
|
375
|
-
cell_name = nil;
|
376
367
|
entry.each do |element|
|
377
368
|
next unless element.name == 'category'
|
378
|
-
cell_name = nil
|
379
369
|
element.each do |item|
|
380
|
-
|
381
|
-
when 'link'
|
382
|
-
cell_name = item['href'][/\/R\d+C\d+/] if item['rel'] == 'self'
|
383
|
-
when 'cell'
|
370
|
+
if item.name == 'cell'
|
384
371
|
row = item['row']
|
385
372
|
col = item['col']
|
386
|
-
value = item['inputvalue'] || item['inputValue']
|
387
|
-
numericvalue = item['numericvalue'] || item['numericValue']
|
388
|
-
if value[0,1] == '='
|
389
|
-
formula = value
|
390
|
-
else
|
391
|
-
formula = nil
|
392
|
-
end
|
393
|
-
@cell_type[sheet] ||= {}
|
394
|
-
if formula
|
395
|
-
ty = :formula
|
396
|
-
if numeric?(numericvalue)
|
397
|
-
value = numericvalue.to_f
|
398
|
-
else
|
399
|
-
value = numericvalue
|
400
|
-
end
|
401
|
-
elsif datetime?(value)
|
402
|
-
ty = :datetime
|
403
|
-
elsif date?(value)
|
404
|
-
ty = :date
|
405
|
-
elsif numeric?(value) # or o.class ???
|
406
|
-
ty = :float
|
407
|
-
value = value.to_f
|
408
|
-
elsif time?(value)
|
409
|
-
ty = :time
|
410
|
-
value = timestring_to_seconds(value)
|
411
|
-
else
|
412
|
-
ty = :string
|
413
|
-
end
|
414
373
|
key = "#{row},#{col}"
|
415
|
-
|
374
|
+
string_value = item['inputvalue'] || item['inputValue']
|
375
|
+
numeric_value = item['numericvalue'] || item['numericValue']
|
376
|
+
(value, value_type) = determine_datatype(string_value, numeric_value)
|
416
377
|
@cell[sheet][key] = value unless value == "" or value == nil
|
417
|
-
@cell_type[sheet][key] =
|
378
|
+
@cell_type[sheet][key] = value_type
|
418
379
|
end
|
419
380
|
@formula[sheet] = {} unless @formula[sheet]
|
420
|
-
@formula[sheet][key] =
|
381
|
+
@formula[sheet][key] = string_value if value_type == :formula
|
421
382
|
end
|
422
383
|
end
|
423
|
-
@cell_name[sheet][key] = cell_name if cell_name && key
|
424
384
|
end
|
425
385
|
@cells_read[sheet] = true
|
426
386
|
end
|
427
|
-
|
428
|
-
def
|
429
|
-
|
387
|
+
|
388
|
+
def determine_datatype(val, numval=nil)
|
389
|
+
if val[0,1] == '='
|
390
|
+
ty = :formula
|
391
|
+
if numeric?(numval)
|
392
|
+
val = numval.to_f
|
393
|
+
else
|
394
|
+
val = numval
|
395
|
+
end
|
396
|
+
else
|
397
|
+
if datetime?(val)
|
398
|
+
ty = :datetime
|
399
|
+
elsif date?(val)
|
400
|
+
ty = :date
|
401
|
+
elsif numeric?(val)
|
402
|
+
ty = :float
|
403
|
+
val = val.to_f
|
404
|
+
elsif time?(val)
|
405
|
+
ty = :time
|
406
|
+
val = timestring_to_seconds(val)
|
407
|
+
else
|
408
|
+
ty = :string
|
409
|
+
end
|
410
|
+
end
|
411
|
+
return val, ty
|
430
412
|
end
|
431
|
-
|
432
|
-
|
433
|
-
|
413
|
+
|
434
414
|
end # class
|
data/lib/roo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hmcgowan-roo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugh McGowan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-05-
|
13
|
+
date: 2009-05-28 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|