roo 1.3.9 → 1.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # README for Roo
2
2
 
3
- 1.3.5 is now available on Rubyforge. You can install the official release with 'gem install roo' or refer to the installation instructions below for the latest development gem.
3
+ Roo is available here and on Rubyforge. You can install the official release with 'gem install roo' or refer to the installation instructions below for the latest development gem.
4
4
 
5
5
 
6
6
  ## Installation
@@ -0,0 +1,53 @@
1
+ require 'soap/rpc/driver'
2
+
3
+ def ferien_fuer_region(proxy, region, year=nil)
4
+ proxy.first_row.upto(proxy.last_row) { |row|
5
+ if proxy.cell(row, 2) == region
6
+ jahr = proxy.cell(row,1).to_i
7
+ if year == nil || jahr == year
8
+ bis_datum = proxy.cell(row,5)
9
+ if DateTime.now > bis_datum
10
+ print '('
11
+ end
12
+ print jahr.to_s+" "
13
+ print proxy.cell(row,2)+" "
14
+ print proxy.cell(row,3)+" "
15
+ print proxy.cell(row,4).to_s+" "
16
+ print bis_datum.to_s+" "
17
+ print (proxy.cell(row,6) || '')+" "
18
+ if DateTime.now > bis_datum
19
+ print ')'
20
+ end
21
+ puts
22
+ end
23
+ end
24
+ }
25
+ end
26
+
27
+ proxy = SOAP::RPC::Driver.new("http://localhost:12321","spreadsheetserver")
28
+ proxy.add_method('cell','row','col')
29
+ proxy.add_method('officeversion')
30
+ proxy.add_method('last_row')
31
+ proxy.add_method('last_column')
32
+ proxy.add_method('first_row')
33
+ proxy.add_method('first_column')
34
+ proxy.add_method('sheets')
35
+ proxy.add_method('set_default_sheet','s')
36
+ proxy.add_method('ferien_fuer_region', 'region')
37
+
38
+ sheets = proxy.sheets
39
+ proxy.set_default_sheet(sheets.first)
40
+
41
+ puts "first row: #{proxy.first_row}"
42
+ puts "first column: #{proxy.first_column}"
43
+ puts "last row: #{proxy.last_row}"
44
+ puts "last column: #{proxy.last_column}"
45
+ puts "cell: #{proxy.cell('C',8)}"
46
+ puts "cell: #{proxy.cell('F',12)}"
47
+ puts "officeversion: #{proxy.officeversion}"
48
+ puts "Berlin:"
49
+
50
+ ferien_fuer_region(proxy, "Berlin")
51
+
52
+
53
+
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'roo'
3
+ require 'soap/rpc/standaloneServer'
4
+
5
+ NS = "spreadsheetserver" # name of your service = namespace
6
+ class Server2 < SOAP::RPC::StandaloneServer
7
+
8
+ def on_init
9
+ spreadsheet = Openoffice.new("./Ferien-de.ods")
10
+ add_method(spreadsheet, 'cell', 'row', 'col')
11
+ add_method(spreadsheet, 'officeversion')
12
+ add_method(spreadsheet, 'first_row')
13
+ add_method(spreadsheet, 'last_row')
14
+ add_method(spreadsheet, 'first_column')
15
+ add_method(spreadsheet, 'last_column')
16
+ add_method(spreadsheet, 'sheets')
17
+ #add_method(spreadsheet, 'default_sheet=', 's')
18
+ # method with '...=' did not work? alias method 'set_default_sheet' created
19
+ add_method(spreadsheet, 'set_default_sheet', 's')
20
+ end
21
+
22
+ end
23
+
24
+ PORT = 12321
25
+ puts "serving at port #{PORT}"
26
+ svr = Server2.new('Roo', NS, '0.0.0.0', PORT)
27
+
28
+ trap('INT') { svr.shutdown }
29
+ svr.start
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'roo'
3
+
4
+ #-- create a new spreadsheet within your google-spreadsheets and paste
5
+ #-- the 'key' parameter in the spreadsheet URL
6
+ MAXTRIES = 1000
7
+ print "what's your name? "
8
+ my_name = gets.chomp
9
+ print "where do you live? "
10
+ my_location = gets.chomp
11
+ print "your message? (if left blank, only your name and location will be inserted) "
12
+ my_message = gets.chomp
13
+ spreadsheet = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
14
+ spreadsheet.default_sheet = 'Sheet1'
15
+ success = false
16
+ MAXTRIES.times do
17
+ col = rand(10)+1
18
+ row = rand(10)+1
19
+ if spreadsheet.empty?(row,col)
20
+ if my_message.empty?
21
+ text = Time.now.to_s+" "+"Greetings from #{my_name} (#{my_location})"
22
+ else
23
+ text = Time.now.to_s+" "+"#{my_message} from #{my_name} (#{my_location})"
24
+ end
25
+ spreadsheet.set_value(row,col,text)
26
+ puts "message written to row #{row}, column #{col}"
27
+ success = true
28
+ break
29
+ end
30
+ puts "Row #{row}, column #{col} already occupied, trying again..."
31
+ end
32
+ puts "no empty cell found within #{MAXTRIES} tries" if !success
33
+
data/lib/roo/google.rb CHANGED
@@ -1,44 +1,64 @@
1
1
  require 'gdata/spreadsheet'
2
2
  require 'xml'
3
3
 
4
+ class GoogleHTTPError < RuntimeError; end
5
+ class GoogleReadError < RuntimeError; end
6
+ class GoogleWriteError < RuntimeError; end
7
+
4
8
  # overwrite some methods from the gdata-gem:
5
9
  module GData
6
10
  class Spreadsheet < GData::Base
11
+
12
+ def visibility
13
+ @headers ? "private" : "public"
14
+ end
15
+
16
+ def projection
17
+ @headers ? "full" : "values"
18
+ end
19
+
7
20
  #-- modified
8
21
  def evaluate_cell(cell, sheet_no=1)
9
22
  raise ArgumentError, "invalid cell: #{cell}" unless cell
10
23
  raise ArgumentError, "invalid sheet_no: #{sheet_no}" unless sheet_no >0 and sheet_no.class == Fixnum
11
- path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{@headers ? "private" : "public"}/basic/#{cell}"
12
-
24
+ path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}/#{cell}"
13
25
  doc = Hpricot(request(path))
14
26
  result = (doc/"content").inner_html
15
27
  end
16
28
 
17
29
  #-- new
18
30
  def sheetlist
19
- path = "/feeds/worksheets/#{@spreadsheet_id}/private/basic"
31
+ path = "/feeds/worksheets/#{@spreadsheet_id}/#{visibility}/#{projection}"
20
32
  doc = Hpricot(request(path))
21
33
  result = []
22
34
  (doc/"content").each { |elem|
23
35
  result << elem.inner_html
24
36
  }
37
+ if result.size == 0
38
+ if (doc/"h2").inner_html =~ /Error/
39
+ raise GoogleHTTPError, "#{(doc/'h2').inner_html}: #{(doc/'title').inner_html} [key '#{@spreadsheet_id}']"
40
+ else
41
+ raise GoogleReadError, "#{doc} [key '#{@spreadsheet_id}']"
42
+ end
43
+ end
25
44
  result
26
45
  end
27
46
 
28
47
  #-- new
29
48
  #@@ added sheet_no to definition
30
49
  def save_entry_roo(entry, sheet_no)
31
- path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{@headers ? 'private' : 'public'}/full"
50
+ raise GoogleWriteError, "unable to write to public spreadsheets" if visibility == 'public'
51
+ path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}"
32
52
  post(path, entry)
33
53
  end
34
54
 
35
55
  #-- new
36
56
  def entry_roo(formula, row=1, col=1)
37
- <<XML
57
+ <<-XML
38
58
  <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'>
39
59
  <gs:cell row='#{row}' col='#{col}' inputValue='#{formula}' />
40
60
  </entry>
41
- XML
61
+ XML
42
62
  end
43
63
 
44
64
  #-- new
@@ -49,13 +69,13 @@ XML
49
69
 
50
70
  #-- new
51
71
  def get_one_sheet
52
- path = "/feeds/cells/#{@spreadsheet_id}/1/private/full"
72
+ path = "/feeds/cells/#{@spreadsheet_id}/1/#{visibility}/#{projection}"
53
73
  doc = Hpricot(request(path))
54
74
  end
55
75
 
56
76
  #new
57
77
  def oben_unten_links_rechts(sheet_no)
58
- path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/private/full"
78
+ path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}"
59
79
  doc = Hpricot(request(path))
60
80
  rows = []
61
81
  cols = []
@@ -67,7 +87,7 @@ XML
67
87
  end
68
88
 
69
89
  def fulldoc(sheet_no)
70
- path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/private/full"
90
+ path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{visibility}/#{projection}"
71
91
  doc = Hpricot(request(path))
72
92
  return doc
73
93
  end
@@ -90,7 +110,6 @@ class Google < GenericSpreadsheet
90
110
  unless password
91
111
  password = ENV['GOOGLE_PASSWORD']
92
112
  end
93
- @default_sheet = nil
94
113
  @cell = Hash.new {|h,k| h[k]=Hash.new}
95
114
  @cell_type = Hash.new {|h,k| h[k]=Hash.new}
96
115
  @formula = Hash.new
@@ -104,11 +123,8 @@ class Google < GenericSpreadsheet
104
123
  @datetime_format = '%d/%m/%Y %H:%M:%S'
105
124
  @time_format = '%H:%M:%S'
106
125
  @gs = GData::Spreadsheet.new(spreadsheetkey)
107
- @gs.authenticate(user, password)
126
+ @gs.authenticate(user, password) unless user.empty? || password.empty?
108
127
  @sheetlist = @gs.sheetlist
109
- #-- ----------------------------------------------------------------------
110
- #-- TODO: Behandlung von Berechtigungen hier noch einbauen ???
111
- #-- ----------------------------------------------------------------------
112
128
  @default_sheet = self.sheets.first
113
129
  end
114
130
 
@@ -192,7 +208,7 @@ class Google < GenericSpreadsheet
192
208
  sheet = @default_sheet unless sheet
193
209
  read_cells(sheet) unless @cells_read[sheet]
194
210
  row,col = normalize(row,col)
195
- if @formula[sheet]["#{row},#{col}"]
211
+ if @formula.size > 0 && @formula[sheet]["#{row},#{col}"]
196
212
  return :formula
197
213
  else
198
214
  @cell_type[sheet]["#{row},#{col}"]
@@ -335,7 +351,7 @@ class Google < GenericSpreadsheet
335
351
  end
336
352
 
337
353
  def determine_datatype(val, numval=nil)
338
- if val[0,1] == '='
354
+ if val.nil? || val[0,1] == '='
339
355
  ty = :formula
340
356
  if numeric?(numval)
341
357
  val = numval.to_f
Binary file
data/test/test_roo.rb CHANGED
@@ -158,6 +158,16 @@ class TestRoo < Test::Unit::TestCase
158
158
  yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google)
159
159
  end
160
160
 
161
+ def with_public_google_spreadsheet(&block)
162
+ user = ENV['GOOGLE_MAIL']
163
+ pass = ENV['GOOGLE_PASSWORD']
164
+ ENV['GOOGLE_MAIL'] = ''
165
+ ENV['GOOGLE_PASSWORD'] = ''
166
+ block.call
167
+ ENV['GOOGLE_MAIL'] = user
168
+ ENV['GOOGLE_PASSWORD'] = pass
169
+ end
170
+
161
171
  # Using Date.strptime so check that it's using the method
162
172
  # with the value set in date_format
163
173
  def test_date
@@ -385,7 +395,7 @@ class TestRoo < Test::Unit::TestCase
385
395
  def test_empty_eh
386
396
  with_each_spreadsheet(:name=>'numbers1') do |oo|
387
397
  assert oo.empty?('a',14)
388
- assert ! oo.empty?('a',15)
398
+ assert !oo.empty?('a',15)
389
399
  assert oo.empty?('a',20)
390
400
  end
391
401
  end
@@ -1199,6 +1209,7 @@ class TestRoo < Test::Unit::TestCase
1199
1209
 
1200
1210
  def test_write_google
1201
1211
  # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
1212
+
1202
1213
  with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1203
1214
  oo.set_value(1,1,"hello from the tests")
1204
1215
  assert_equal "hello from the tests", oo.cell(1,1)
@@ -1345,7 +1356,7 @@ Sheet 3:
1345
1356
 
1346
1357
  def test_no_remaining_tmp_files_google
1347
1358
  if GOOGLE
1348
- assert_nothing_raised() {
1359
+ assert_raise(GoogleReadError) {
1349
1360
  oo = Google.new(key_of("no_spreadsheet_file.txt"))
1350
1361
  }
1351
1362
  a=Dir.glob("oo_*")
@@ -1780,5 +1791,32 @@ Sheet 3:
1780
1791
  assert_equal :date, oo.celltype(1,1)
1781
1792
  end
1782
1793
  end
1794
+
1795
+
1796
+ def test_bad_excel_date
1797
+ with_each_spreadsheet(:name=>'bad_exceL_date', :format=>:excel) do |oo|
1798
+ assert_nothing_raised(ArgumentError) {
1799
+ assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1)
1800
+ }
1801
+ end
1802
+ end
1803
+
1804
+ def test_public_google_doc
1805
+ with_public_google_spreadsheet do
1806
+ assert_raise(GoogleHTTPError) { Google.new("foo") }
1807
+ assert_raise(GoogleReadError) { Google.new(key_of('numbers1'))}
1808
+ assert_nothing_raised { Google.new("0AncOJVyN5MMMcjZtN0hGbFVPd3N0MFJUVVR1aFEwT3c") } # use spreadsheet key (private)
1809
+ assert_nothing_raised { Google.new(key_of('write.me')) } # use spreadsheet key (public)
1810
+ end
1811
+ end
1812
+
1813
+ def test_public_google_doc_write
1814
+ with_public_google_spreadsheet do
1815
+ assert_raise(GoogleWriteError) {
1816
+ oo = Google.new(key_of('write.me'))
1817
+ oo.set_value(1,1,'test')
1818
+ }
1819
+ end
1820
+ end
1783
1821
 
1784
1822
  end # class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9
4
+ version: 1.3.11
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-07-23 00:00:00 -05:00
13
+ date: 2009-08-31 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -70,9 +70,10 @@ executables: []
70
70
  extensions: []
71
71
 
72
72
  extra_rdoc_files:
73
- - README.markdown
74
73
  - History.txt
74
+ - README.markdown
75
75
  files:
76
+ - lib/roo.rb
76
77
  - lib/roo/excel.rb
77
78
  - lib/roo/excelx.rb
78
79
  - lib/roo/generic_spreadsheet.rb
@@ -80,17 +81,17 @@ files:
80
81
  - lib/roo/openoffice.rb
81
82
  - lib/roo/roo_rails_helper.rb
82
83
  - lib/roo/version.rb
83
- - lib/roo.rb
84
84
  - test/1900_base.xls
85
85
  - test/1904_base.xls
86
- - test/bbu.ods
87
- - test/bbu.xls
88
- - test/bbu.xlsx
89
86
  - test/Bibelbund.csv
90
87
  - test/Bibelbund.ods
91
88
  - test/Bibelbund.xls
92
89
  - test/Bibelbund.xlsx
93
90
  - test/Bibelbund1.ods
91
+ - test/bad_excel_date.xls
92
+ - test/bbu.ods
93
+ - test/bbu.xls
94
+ - test/bbu.xlsx
94
95
  - test/bode-v1.ods.zip
95
96
  - test/bode-v1.xls.zip
96
97
  - test/boolean.ods
@@ -142,8 +143,8 @@ files:
142
143
  - test/whitespace.ods
143
144
  - test/whitespace.xls
144
145
  - test/whitespace.xlsx
145
- - README.markdown
146
146
  - History.txt
147
+ - README.markdown
147
148
  has_rdoc: true
148
149
  homepage: http://roo.rubyforge.org
149
150
  licenses: []
@@ -152,8 +153,6 @@ post_install_message:
152
153
  rdoc_options:
153
154
  - --main
154
155
  - README.markdown
155
- - --inline-source
156
- - --charset=UTF-8
157
156
  require_paths:
158
157
  - lib
159
158
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -171,9 +170,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
170
  requirements: []
172
171
 
173
172
  rubyforge_project: roo
174
- rubygems_version: 1.3.3
173
+ rubygems_version: 1.3.5
175
174
  signing_key:
176
175
  specification_version: 3
177
176
  summary: roo
178
- test_files: []
179
-
177
+ test_files:
178
+ - test/skipped_tests.rb
179
+ - test/test_helper.rb
180
+ - test/test_roo.rb
181
+ - examples/roo_soap_client.rb
182
+ - examples/roo_soap_server.rb
183
+ - examples/write_me.rb