roo 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.8.3 2007-12-31
2
+ * 2 bugfixes
3
+ * another fix for the encoding issue in excel sheet-names
4
+ * reactived the Excel#find method which has been disappeared in the last restructoring, moved to GenericSpreadsheet
1
5
  == 0.8.2 2007-12-28
2
6
  * 1 enhancement:
3
7
  * basename() only in method #info
data/lib/roo/excel.rb CHANGED
@@ -65,6 +65,7 @@ class Excel < GenericSpreadsheet
65
65
  @workbook.worksheet(i).name
66
66
  )
67
67
  else
68
+ # result << platform_specific_iconv(inject_null_characters(@workbook.worksheet(i).name))
68
69
  result << platform_specific_iconv(@workbook.worksheet(i).name)
69
70
  #case RUBY_PLATFORM.downcase
70
71
  #when /darwin/
@@ -81,6 +82,19 @@ class Excel < GenericSpreadsheet
81
82
  return result
82
83
  end
83
84
 
85
+ #TODO: testing only
86
+ def inject_null_characters(str)
87
+ if str.class != String
88
+ return str
89
+ end
90
+ new_str=''
91
+ 0.upto(str.size-1) do |i|
92
+ new_str += str[i,1]
93
+ new_str += "\000"
94
+ end
95
+ new_str
96
+ end
97
+
84
98
  # sets the working sheet (1,2,3,..)
85
99
  def default_sheet=(n)
86
100
  if n.kind_of?(Fixnum)
@@ -311,10 +325,10 @@ class Excel < GenericSpreadsheet
311
325
  0.upto(@workbook.sheet_count - 1) do |i|
312
326
  # TODO: is there a better way to do conversion?
313
327
  return i if name == platform_specific_iconv(
314
- @workbook.worksheet(i).name)
315
- #Iconv.new('utf-8','unicode').iconv(
316
- # @workbook.worksheet(i).name
317
- # )
328
+ @workbook.worksheet(i).name)
329
+ #Iconv.new('utf-8','unicode').iconv(
330
+ # @workbook.worksheet(i).name
331
+ # )
318
332
  end
319
333
  raise StandardError, "sheet '#{name}' not found"
320
334
  end
@@ -330,16 +344,41 @@ class Excel < GenericSpreadsheet
330
344
  ! content
331
345
  end
332
346
 
333
- def platform_specific_iconv(value)
334
- case RUBY_PLATFORM.downcase
335
- when /darwin/
336
- result = Iconv.new('utf-8','utf-8').iconv(value)
337
- when /mswin32/
338
- result = Iconv.new('utf-8','iso-8859-1').iconv(value)
339
- else
340
- result = Iconv.new('utf-8','unicode').iconv(value)
341
- end # case
342
- result
343
- end
347
+ def platform_specific_iconv(value)
348
+ case RUBY_PLATFORM.downcase
349
+ when /darwin/
350
+ result = Iconv.new('utf-8','utf-8').iconv(value)
351
+ when /mswin32/
352
+ result = Iconv.new('utf-8','iso-8859-1').iconv(value)
353
+ else
354
+ result = Iconv.new('utf-8','unicode').iconv(value)
355
+ end # case
356
+ if every_second_null?(result)
357
+ result = remove_every_second_null(result)
358
+ end
359
+ result
360
+ end
361
+
362
+ def every_second_null?(str)
363
+ result = true
364
+ 0.upto(str.length/2-1) do |i|
365
+ c = str[i*2,1]
366
+ n = str[i*2+1,1]
367
+ if n != "\000"
368
+ result = false
369
+ break
370
+ end
371
+ end
372
+ result
373
+ end
374
+
375
+ def remove_every_second_null(str)
376
+ result = ''
377
+ 0.upto(str.length/2-1) do |i|
378
+ c = str[i*2,1]
379
+ result += c
380
+ end
381
+ result
382
+ end
344
383
 
345
384
  end
@@ -258,7 +258,7 @@ class GenericSpreadsheet
258
258
  result
259
259
  end
260
260
 
261
- # write the current spreadsheet to stdout or into a file
261
+ # write the current spreadsheet to stdout or into a file
262
262
  #TODO: refactoring --> GenericSpreadsheet
263
263
 
264
264
  def to_csv(filename=nil,sheet=nil)
@@ -273,6 +273,85 @@ class GenericSpreadsheet
273
273
  true
274
274
  end
275
275
 
276
+ # find a row either by row number or a condition
277
+ # Caution: this works only within the default sheet -> set default_sheet before you call this method
278
+ # (experimental. see examples in the test_roo.rb file)
279
+ def find(*args) # :nodoc
280
+ result_array = false
281
+ args.each {|arg,val|
282
+ if arg.class == Hash
283
+ arg.each { |hkey,hval|
284
+ if hkey == :array and hval == true
285
+ result_array = true
286
+ end
287
+ }
288
+ end
289
+ }
290
+ column_with = {}
291
+ 1.upto(last_column) do |col|
292
+ column_with[cell(@header_line,col)] = col
293
+ end
294
+ result = Array.new
295
+ #-- id
296
+ if args[0].class == Fixnum
297
+ rownum = args[0]
298
+ tmp = {}
299
+ 1.upto(self.row(rownum).size) {|j|
300
+ x = ''
301
+ column_with.each { |key,val|
302
+ if val == j
303
+ x = key
304
+ end
305
+ }
306
+ tmp[x] = cell(rownum,j)
307
+ }
308
+ result = [ tmp ] # row(rownum)
309
+ #-- :all
310
+ elsif args[0] == :all
311
+ if args[1].class == Hash
312
+ args[1].each {|key,val|
313
+ if key == :conditions
314
+ column_with = {}
315
+ 1.upto(last_column) do |col|
316
+ column_with[cell(@header_line,col)] = col
317
+ end
318
+ conditions = val
319
+ first_row.upto(last_row) do |i|
320
+ # are all conditions met?
321
+ found = 1
322
+ conditions.each { |key,val|
323
+ if cell(i,column_with[key]) == val
324
+ found *= 1
325
+ else
326
+ found *= 0
327
+ end
328
+ }
329
+ # p self.row(i) if found > 0
330
+ if found > 0
331
+ tmp = {}
332
+ 1.upto(self.row(i).size) {|j|
333
+ x = ''
334
+ column_with.each { |key,val|
335
+ if val == j
336
+ x = key
337
+ end
338
+ }
339
+ tmp[x] = cell(i,j)
340
+ }
341
+ if result_array
342
+ result << self.row(i)
343
+ else
344
+ result << tmp
345
+ end
346
+ end
347
+ end
348
+ end # :conditions
349
+ }
350
+ end
351
+ end
352
+ result
353
+ end
354
+
276
355
  protected
277
356
 
278
357
  def unzip(filename)
data/lib/roo/google.rb CHANGED
@@ -323,22 +323,6 @@ class Google < GenericSpreadsheet
323
323
  return @last_column[sheet]
324
324
  end
325
325
 
326
- # # write the current spreadsheet to stdout or into a file
327
- # #--
328
- # #TODO: refactoring --> GenericSpreadsheet
329
- # def to_csv(filename=nil,sheet=nil)
330
- # sheet = @default_sheet unless sheet
331
- # if filename
332
- # file = File.open(filename,"w") # do |file|
333
- # write_csv_content(file,sheet)
334
- # file.close
335
- # else
336
- # write_csv_content(STDOUT,sheet)
337
- # end
338
- # true
339
- # end
340
-
341
-
342
326
  # find a row either by row number or a condition
343
327
  # Caution: this works only within the default sheet -> set default_sheet before you call this method
344
328
  # (experimental. see examples in the test_roo.rb file)
@@ -504,67 +488,5 @@ class Google < GenericSpreadsheet
504
488
  end
505
489
  end
506
490
 
507
- # #TODO: refactoring to GenericSpreadsheet?
508
- # def write_csv_content(file=nil,sheet=nil)
509
- # file = STDOUT unless file
510
- # if first_row # sheet is not empty
511
- # first_row(sheet).upto(last_row(sheet)) do |row|
512
- # 1.upto(last_column(sheet)) do |col|
513
- # file.print(",") if col > 1
514
- # onecell = cell(row,col,sheet)
515
- # onecelltype = celltype(row,col,sheet)
516
- # file.print one_cell_output(onecelltype,onecell,empty?(row,col,sheet))
517
- # end
518
- # file.print("\n")
519
- # end # sheet not empty
520
- # end
521
- # end
522
-
523
- # #TODO: refactor to Generic....
524
- # def one_cell_output(onecelltype,onecell,empty)
525
- # str = ""
526
- # if empty
527
- # str += ''
528
- # else
529
- # case onecelltype
530
- # when :string
531
- # if onecell == ""
532
- # str << ''
533
- # else
534
- # onecell.gsub!(/"/,'""')
535
- # str << ('"'+onecell+'"')
536
- # end
537
- # when :float,:percentage
538
- # if onecell == onecell.to_i
539
- # str << onecell.to_i.to_s
540
- # else
541
- # str << onecell.to_s
542
- # end
543
- # when :formula
544
- # if onecell.class == String
545
- # if onecell == ""
546
- # str << ''
547
- # else
548
- # onecell.gsub!(/"/,'""')
549
- # str << '"'+onecell+'"'
550
- # end
551
- # elsif onecell.class == Float
552
- # if onecell == onecell.to_i
553
- # str << onecell.to_i.to_s
554
- # else
555
- # str << onecell.to_s
556
- # end
557
- # else
558
- # raise "unhandled onecell-class "+onecell.class.to_s
559
- # end
560
- # when :date
561
- # str << '"'+onecell.to_s+'"'
562
- # else
563
- # raise "unhandled celltype "+onecelltype.to_s
564
- # end
565
- # end
566
- # #cells << onecell
567
- # str
568
- # end
569
491
 
570
492
  end # class
@@ -283,86 +283,6 @@ class Openoffice < GenericSpreadsheet
283
283
  # true
284
284
  # end
285
285
 
286
- # find a row either by row number or a condition
287
- # Caution: this works only within the default sheet -> set default_sheet before you call this method
288
- # (experimental. see examples in the test_roo.rb file)
289
- def find(*args)
290
- result_array = false
291
- args.each {|arg,val|
292
- if arg.class == Hash
293
- arg.each { |hkey,hval|
294
- if hkey == :array and hval == true
295
- result_array = true
296
- end
297
- }
298
- end
299
- }
300
- column_with = {}
301
- 1.upto(last_column) do |col|
302
- column_with[cell(@header_line,col)] = col
303
- end
304
- result = Array.new
305
- #-- id
306
- if args[0].class == Fixnum
307
- rownum = args[0]
308
- tmp = {}
309
- 1.upto(self.row(rownum).size) {|j|
310
- x = ''
311
- column_with.each { |key,val|
312
- if val == j
313
- x = key
314
- end
315
- }
316
- tmp[x] = cell(rownum,j)
317
- }
318
- result = [ tmp ] # row(rownum)
319
- #-- :all
320
- elsif args[0] == :all
321
- if args[1].class == Hash
322
- args[1].each {|key,val|
323
- if key == :conditions
324
- column_with = {}
325
- 1.upto(last_column) do |col|
326
- column_with[cell(@header_line,col)] = col
327
- end
328
- conditions = val
329
- first_row.upto(last_row) do |i|
330
- # are all conditions met?
331
- found = 1
332
- conditions.each { |key,val|
333
- if cell(i,column_with[key]) == val
334
- found *= 1
335
- else
336
- found *= 0
337
- end
338
- }
339
- # p self.row(i) if found > 0
340
- if found > 0
341
- tmp = {}
342
- 1.upto(self.row(i).size) {|j|
343
- x = ''
344
- column_with.each { |key,val|
345
- if val == j
346
- x = key
347
- end
348
- }
349
- tmp[x] = cell(i,j)
350
- }
351
- if result_array
352
- result << self.row(i)
353
- else
354
- result << tmp
355
- end
356
- end
357
- end
358
- end # :conditions
359
- }
360
- end
361
- end
362
- result
363
- end
364
-
365
-
366
286
  private
367
287
 
368
288
  # read the version of the OO-Version
data/lib/roo/version.rb CHANGED
@@ -2,7 +2,7 @@ module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 8
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/test_roo.rb CHANGED
@@ -27,7 +27,7 @@ if DB_LOG
27
27
  # require 'activerecord'
28
28
  # require_gem 'activerecord', '< 2.0.0'
29
29
  #gem 'activerecord', '< 2.0.0'
30
- require 'activerecord'
30
+ require 'activerecord'
31
31
  end
32
32
 
33
33
  include FileUtils
@@ -59,7 +59,7 @@ class Test::Unit::TestCase
59
59
  }[spreadsheetname]
60
60
  rescue
61
61
  raise "unknown spreadsheetname: #{spreadsheetname}"
62
- end
62
+ end
63
63
  end
64
64
 
65
65
  if DB_LOG
@@ -106,7 +106,7 @@ class File
106
106
 
107
107
  def File.delete_if_exist(filename)
108
108
  if File.exist?(filename)
109
- File.delete(filename)
109
+ File.delete(filename)
110
110
  end
111
111
  end
112
112
 
@@ -121,7 +121,6 @@ class TestRoo < Test::Unit::TestCase
121
121
  OPENOFFICEWRITE = false # experimental: write access with OO-Documents
122
122
  ONLINE = true
123
123
  LONG_RUN = false
124
- LONG_RUN_EXCEL = false
125
124
  GLOBAL_TIMEOUT = 2*12*60 # seconds
126
125
 
127
126
 
@@ -475,7 +474,7 @@ class TestRoo < Test::Unit::TestCase
475
474
  end
476
475
  end
477
476
 
478
- #TODO: inkonsequente Lieferung Fixnum/Float
477
+ #TODO: inkonsequente Lieferung Fixnum/Float
479
478
  def test_rows
480
479
  if OPENOFFICE
481
480
  oo = Openoffice.new(File.join("test","numbers1.ods"))
@@ -624,18 +623,18 @@ class TestRoo < Test::Unit::TestCase
624
623
  assert_equal 1, oo.first_column
625
624
  end
626
625
  if GOOGLE
627
- assert_nothing_raised(Timeout::Error) {
628
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
629
- oo = Google.new(key_of("numbers1"))
630
- oo.default_sheet = oo.sheets.first
631
- assert_equal 1, oo.first_column
632
- end
633
- }
626
+ assert_nothing_raised(Timeout::Error) {
627
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
628
+ oo = Google.new(key_of("numbers1"))
629
+ oo.default_sheet = oo.sheets.first
630
+ assert_equal 1, oo.first_column
631
+ end
632
+ }
634
633
  end
635
634
  end
636
635
 
637
636
  def test_first_column_as_letter_openoffice
638
- if OPENOFFICE
637
+ if OPENOFFICE
639
638
  oo = Openoffice.new(File.join("test","numbers1.ods"))
640
639
  oo.default_sheet = oo.sheets.first
641
640
  assert_equal 'A', oo.first_column_as_letter
@@ -734,11 +733,11 @@ end
734
733
  oo.default_sheet = "Tabelle1"
735
734
  }
736
735
  end
737
- assert_nothing_raised(ArgumentError) {
738
- # oo.default_sheet = 1
739
- #oo.default_sheet = "first sheet"
740
- oo.default_sheet = "Tabelle1"
741
- }
736
+ assert_nothing_raised(ArgumentError) {
737
+ # oo.default_sheet = 1
738
+ #oo.default_sheet = "first sheet"
739
+ oo.default_sheet = "Tabelle1"
740
+ }
742
741
  end
743
742
  end
744
743
 
@@ -1081,32 +1080,32 @@ end
1081
1080
  end
1082
1081
  end
1083
1082
  if GOOGLE
1084
- oo = Google.new(key_of("formula"))
1085
- oo.default_sheet = oo.sheets.first
1086
- assert_equal 1, oo.cell('A',1)
1087
- assert_equal 2, oo.cell('A',2)
1088
- assert_equal 3, oo.cell('A',3)
1089
- assert_equal 4, oo.cell('A',4)
1090
- assert_equal 5, oo.cell('A',5)
1091
- assert_equal 6, oo.cell('A',6)
1092
- # assert_equal 21, oo.cell('A',7)
1093
- assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
1094
- assert_equal :formula, oo.celltype('A',7)
1095
- # assert_equal "=[Sheet2.A1]", oo.formula('C',7)
1096
- # !!! different from formulas in Openoffice
1097
- assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
1098
- assert_nil oo.formula('A',6)
1099
- # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
1100
- # [7, 2, "=SUM([.$A$1:.B6])"],
1101
- # [7, 3, "=[Sheet2.A1]"],
1102
- # [8, 2, "=SUM([.$A$1:.B7])"],
1103
- # ], oo.formulas(oo.sheets.first)
1104
- # different format than in openoffice spreadsheets:
1105
- assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
1106
- [7, 2, "=SUM(R1C1:R[-1]C[0])"],
1107
- [7, 3, "=sheet2!R[-6]C[-2]"],
1108
- [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
1109
- oo.formulas(oo.sheets.first)
1083
+ oo = Google.new(key_of("formula"))
1084
+ oo.default_sheet = oo.sheets.first
1085
+ assert_equal 1, oo.cell('A',1)
1086
+ assert_equal 2, oo.cell('A',2)
1087
+ assert_equal 3, oo.cell('A',3)
1088
+ assert_equal 4, oo.cell('A',4)
1089
+ assert_equal 5, oo.cell('A',5)
1090
+ assert_equal 6, oo.cell('A',6)
1091
+ # assert_equal 21, oo.cell('A',7)
1092
+ assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
1093
+ assert_equal :formula, oo.celltype('A',7)
1094
+ # assert_equal "=[Sheet2.A1]", oo.formula('C',7)
1095
+ # !!! different from formulas in Openoffice
1096
+ assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
1097
+ assert_nil oo.formula('A',6)
1098
+ # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
1099
+ # [7, 2, "=SUM([.$A$1:.B6])"],
1100
+ # [7, 3, "=[Sheet2.A1]"],
1101
+ # [8, 2, "=SUM([.$A$1:.B7])"],
1102
+ # ], oo.formulas(oo.sheets.first)
1103
+ # different format than in openoffice spreadsheets:
1104
+ assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
1105
+ [7, 2, "=SUM(R1C1:R[-1]C[0])"],
1106
+ [7, 3, "=sheet2!R[-6]C[-2]"],
1107
+ [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
1108
+ oo.formulas(oo.sheets.first)
1110
1109
  end # GOOGLE
1111
1110
  end
1112
1111
 
@@ -1154,36 +1153,36 @@ end
1154
1153
  assert_equal 5, oo.first_column
1155
1154
  assert_equal 9, oo.last_column
1156
1155
  end
1157
- end
1156
+ end
1158
1157
 
1159
1158
  def test_borders_sheets_google
1160
1159
  if GOOGLE
1161
- assert_nothing_raised(Timeout::Error) {
1162
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1163
- oo = Google.new(key_of("borders"))
1164
- oo.default_sheet = oo.sheets[0]
1165
- assert_equal oo.sheets.first, oo.default_sheet
1166
- assert_equal 5, oo.first_row
1167
- oo.default_sheet = oo.sheets[1]
1168
- assert_equal 'Sheet2', oo.default_sheet
1169
- assert_equal 6, oo.first_row
1170
- assert_equal 11, oo.last_row
1171
- assert_equal 4, oo.first_column
1172
- assert_equal 8, oo.last_column
1173
-
1174
- oo.default_sheet = oo.sheets.first
1175
- assert_equal 5, oo.first_row
1176
- assert_equal 10, oo.last_row
1177
- assert_equal 3, oo.first_column
1178
- assert_equal 7, oo.last_column
1160
+ assert_nothing_raised(Timeout::Error) {
1161
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1162
+ oo = Google.new(key_of("borders"))
1163
+ oo.default_sheet = oo.sheets[0]
1164
+ assert_equal oo.sheets.first, oo.default_sheet
1165
+ assert_equal 5, oo.first_row
1166
+ oo.default_sheet = oo.sheets[1]
1167
+ assert_equal 'Sheet2', oo.default_sheet
1168
+ assert_equal 6, oo.first_row
1169
+ assert_equal 11, oo.last_row
1170
+ assert_equal 4, oo.first_column
1171
+ assert_equal 8, oo.last_column
1179
1172
 
1180
- oo.default_sheet = oo.sheets[2]
1181
- assert_equal 7, oo.first_row
1182
- assert_equal 12, oo.last_row
1183
- assert_equal 5, oo.first_column
1184
- assert_equal 9, oo.last_column
1185
- end
1186
- }
1173
+ oo.default_sheet = oo.sheets.first
1174
+ assert_equal 5, oo.first_row
1175
+ assert_equal 10, oo.last_row
1176
+ assert_equal 3, oo.first_column
1177
+ assert_equal 7, oo.last_column
1178
+
1179
+ oo.default_sheet = oo.sheets[2]
1180
+ assert_equal 7, oo.first_row
1181
+ assert_equal 12, oo.last_row
1182
+ assert_equal 5, oo.first_column
1183
+ assert_equal 9, oo.last_column
1184
+ end
1185
+ }
1187
1186
  end
1188
1187
  end
1189
1188
 
@@ -1554,7 +1553,7 @@ end
1554
1553
  end
1555
1554
 
1556
1555
  def test_huge_document_to_csv_excel
1557
- if LONG_RUN_EXCEL
1556
+ if LONG_RUN
1558
1557
  if EXCEL
1559
1558
  assert_nothing_raised(Timeout::Error) {
1560
1559
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
@@ -1571,64 +1570,64 @@ end
1571
1570
  end # def to_csv
1572
1571
 
1573
1572
  def test_huge_document_to_csv_google
1574
- # maybe a better example... TODO:
1575
- after Date.new(2008,1,30) do
1576
- if GOOGLE
1577
- assert_nothing_raised(Timeout::Error) {
1578
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1579
- File.delete("/tmp/numbers1.csv") if File.exists?("/tmp/numbers1.csv")
1580
- oo = Google.new(key_of('numbers1'))
1581
- oo.default_sheet = oo.sheets.first
1582
- #?? assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
1583
- #?? assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
1584
- #?? assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
1585
- assert oo.to_csv("/tmp/numbers1.csv")
1586
- assert File.exists?("/tmp/numbers1.csv")
1587
- assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
1588
- end # Timeout
1589
- } # nothing_raised
1590
- end # GOOGLE
1591
- end # after
1592
- end
1593
-
1594
- def test_to_csv_openoffice
1595
- if OPENOFFICE
1596
- #assert_nothing_raised(Timeout::Error) {
1573
+ # maybe a better example... TODO:
1574
+ after Date.new(2008,1,30) do
1575
+ if GOOGLE
1576
+ assert_nothing_raised(Timeout::Error) {
1597
1577
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1598
- File.delete_if_exist("/tmp/numbers1.csv")
1599
- oo = Openoffice.new(File.join("test","numbers1.ods"))
1578
+ File.delete("/tmp/numbers1.csv") if File.exists?("/tmp/numbers1.csv")
1579
+ oo = Google.new(key_of('numbers1'))
1600
1580
  oo.default_sheet = oo.sheets.first
1601
- #assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
1602
- #assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
1603
- #assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
1581
+ #?? assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
1582
+ #?? assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
1583
+ #?? assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
1604
1584
  assert oo.to_csv("/tmp/numbers1.csv")
1605
1585
  assert File.exists?("/tmp/numbers1.csv")
1606
1586
  assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
1607
1587
  end # Timeout
1608
- #} # nothing_raised
1609
- end # OPENOFFICE
1588
+ } # nothing_raised
1589
+ end # GOOGLE
1590
+ end # after
1591
+ end
1592
+
1593
+ def test_to_csv_openoffice
1594
+ if OPENOFFICE
1595
+ #assert_nothing_raised(Timeout::Error) {
1596
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1597
+ File.delete_if_exist("/tmp/numbers1.csv")
1598
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
1599
+ oo.default_sheet = oo.sheets.first
1600
+ #assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
1601
+ #assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
1602
+ #assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
1603
+ assert oo.to_csv("/tmp/numbers1.csv")
1604
+ assert File.exists?("/tmp/numbers1.csv")
1605
+ assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
1606
+ end # Timeout
1607
+ #} # nothing_raised
1608
+ end # OPENOFFICE
1610
1609
  end
1611
1610
 
1612
1611
  def test_to_csv_excel
1613
- if EXCEL
1614
- #assert_nothing_raised(Timeout::Error) {
1615
- Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1616
- File.delete_if_exist("/tmp/numbers1_excel.csv")
1617
- oo = Excel.new(File.join("test","numbers1.xls"))
1618
- oo.default_sheet = oo.sheets.first
1619
- assert oo.to_csv("/tmp/numbers1_excel.csv")
1620
- assert File.exists?("/tmp/numbers1_excel.csv")
1621
- assert_equal "", `diff test/numbers1_excel.csv /tmp/numbers1_excel.csv`
1622
- end
1623
- #}
1612
+ if EXCEL
1613
+ #assert_nothing_raised(Timeout::Error) {
1614
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1615
+ File.delete_if_exist("/tmp/numbers1_excel.csv")
1616
+ oo = Excel.new(File.join("test","numbers1.xls"))
1617
+ oo.default_sheet = oo.sheets.first
1618
+ assert oo.to_csv("/tmp/numbers1_excel.csv")
1619
+ assert File.exists?("/tmp/numbers1_excel.csv")
1620
+ assert_equal "", `diff test/numbers1_excel.csv /tmp/numbers1_excel.csv`
1624
1621
  end
1622
+ #}
1623
+ end
1625
1624
  end # def to_csv
1626
1625
 
1627
1626
  def test_to_csv_google
1628
- # maybe a better example... TODO:
1629
- after Date.new(2008,1,30) do
1630
- if GOOGLE
1631
- #assert_nothing_raised(Timeout::Error) {
1627
+ # maybe a better example... TODO:
1628
+ after Date.new(2008,1,30) do
1629
+ if GOOGLE
1630
+ #assert_nothing_raised(Timeout::Error) {
1632
1631
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1633
1632
  File.delete_if_exist("/tmp/numbers1.csv") if File.exists?("/tmp/numbers1.csv")
1634
1633
  oo = Google.new(key_of('numbers1'))
@@ -1640,9 +1639,9 @@ after Date.new(2008,1,30) do
1640
1639
  assert File.exists?("/tmp/numbers1.csv")
1641
1640
  assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
1642
1641
  end # Timeout
1643
- #} # nothing_raised
1644
- end # GOOGLE
1645
- end # after
1642
+ #} # nothing_raised
1643
+ end # GOOGLE
1644
+ end # after
1646
1645
  end
1647
1646
 
1648
1647
  def test_bug_mehrere_datum
@@ -1891,6 +1890,55 @@ end # after
1891
1890
  end
1892
1891
  end
1893
1892
 
1893
+ def test_find_by_row_openoffice
1894
+ if OPENOFFICE
1895
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
1896
+ oo.default_sheet = oo.sheets.first
1897
+ rec = oo.find 16
1898
+ assert rec
1899
+ after Date.new(2008,1,15) do
1900
+ # assert_equal "einundvierzig", rec[0]
1901
+ assert_equal false, rec
1902
+
1903
+ rec = oo.find 15
1904
+ assert rec
1905
+ assert_equal 41,rec
1906
+ end
1907
+ end
1908
+ end
1909
+
1910
+ def test_find_by_row_excel
1911
+ if EXCEL
1912
+ oo = Excel.new(File.join("test","numbers1.xls"))
1913
+ oo.default_sheet = oo.sheets.first
1914
+ rec = oo.find 16
1915
+ assert rec
1916
+ after Date.new(2008,1,15) do
1917
+ assert_equal "einundvierzig", rec[0]
1918
+
1919
+ rec = oo.find 15
1920
+ assert rec
1921
+ assert_equal 41,rec[0]
1922
+ end
1923
+ end
1924
+ end
1925
+
1926
+ def test_find_by_row_google
1927
+ if GOOGLE
1928
+ oo = Excel.new(key_of("numbers1"))
1929
+ oo.default_sheet = oo.sheets.first
1930
+ rec = oo.find 16
1931
+ assert rec
1932
+ after Date.new(2008,1,15) do
1933
+ assert_equal "einundvierzig", rec[0]
1934
+
1935
+ rec = oo.find 15
1936
+ assert rec
1937
+ assert_equal 41,rec[0]
1938
+ end
1939
+ end
1940
+ end
1941
+
1894
1942
  def test_find_by_row_huge_document_google
1895
1943
  if LONG_RUN
1896
1944
  if GOOGLE
@@ -2215,12 +2263,10 @@ end # after
2215
2263
  if EXCEL
2216
2264
  assert_nothing_raised(Timeout::Error) {
2217
2265
  Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
2218
- #puts Time.now.to_s + "column Excel gestartet"
2219
2266
  oo = Excel.new(File.join('test','Bibelbund.xls'))
2220
2267
  oo.default_sheet = oo.sheets.first
2221
- #assert_equal 3735, oo.column('a').size
2222
- assert_equal 499, oo.column('a').size
2223
- #puts Time.now.to_s + "column Excel beendet"
2268
+ assert_equal 3735, oo.column('a').size
2269
+ #assert_equal 499, oo.column('a').size
2224
2270
  end
2225
2271
  }
2226
2272
  end
@@ -2257,21 +2303,34 @@ end # after
2257
2303
  assert_equal "Task 1" , erg[1]['Comment']
2258
2304
  end
2259
2305
 
2306
+ def test_simple_spreadsheet_find_by_condition_excel
2307
+ oo = Excel.new(File.join("test","simple_spreadsheet.xls"))
2308
+ oo.default_sheet = oo.sheets.first
2309
+ oo.header_line = 3
2310
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
2311
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
2312
+ assert_equal 10.75 , erg[1]['Start time']
2313
+ assert_equal 12.50 , erg[1]['End time']
2314
+ assert_equal 0 , erg[1]['Pause']
2315
+ assert_equal 1.75 , erg[1]['Sum']
2316
+ assert_equal "Task 1" , erg[1]['Comment']
2317
+ end
2318
+
2260
2319
  def test_simple_spreadsheet_find_by_condition_google
2261
2320
  if GOOGLE
2262
- after Date.new(2007,12,15) do
2263
- oo = Google.new(key_of("simple_spreadsheet"))
2264
- oo.default_sheet = oo.sheets.first
2265
- oo.header_line = 3
2266
- erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
2267
- assert_equal Date.new(2007,05,07), erg[1]['Date']
2268
- assert_equal 10.75 , erg[1]['Start time']
2269
- assert_equal 12.50 , erg[1]['End time']
2270
- assert_equal 0 , erg[1]['Pause']
2271
- assert_kind_of Float, erg[1]['Sum']
2272
- assert_equal 1.75 , erg[1]['Sum']
2273
- assert_equal "Task 1" , erg[1]['Comment']
2274
- end
2321
+ after Date.new(2007,12,15) do
2322
+ oo = Google.new(key_of("simple_spreadsheet"))
2323
+ oo.default_sheet = oo.sheets.first
2324
+ oo.header_line = 3
2325
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
2326
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
2327
+ assert_equal 10.75 , erg[1]['Start time']
2328
+ assert_equal 12.50 , erg[1]['End time']
2329
+ assert_equal 0 , erg[1]['Pause']
2330
+ assert_kind_of Float, erg[1]['Sum']
2331
+ assert_equal 1.75 , erg[1]['Sum']
2332
+ assert_equal "Task 1" , erg[1]['Comment']
2333
+ end
2275
2334
  end
2276
2335
  end
2277
2336
 
@@ -2386,7 +2445,7 @@ end
2386
2445
  ext = ""
2387
2446
  expected = sprintf(expected_templ,ext)
2388
2447
  oo = Google.new(key_of("numbers1"))
2389
- #$log.debug(expected)
2448
+ #$log.debug(expected)
2390
2449
  assert_equal expected.gsub(/numbers1/,key_of("numbers1")), oo.info
2391
2450
  end
2392
2451
  end
@@ -2432,11 +2491,11 @@ end
2432
2491
  }
2433
2492
  end
2434
2493
  if GOOGLE
2435
- after Date.new(2008,1,1) do
2436
- assert_raise(IOError) {
2437
- oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
2438
- }
2439
- end
2494
+ after Date.new(2008,1,1) do
2495
+ assert_raise(IOError) {
2496
+ oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
2497
+ }
2498
+ end
2440
2499
  end
2441
2500
  end
2442
2501
 
@@ -2453,7 +2512,7 @@ end
2453
2512
  end
2454
2513
 
2455
2514
  def test_write_google
2456
- # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
2515
+ # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
2457
2516
  if GOOGLE
2458
2517
  oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
2459
2518
  oo.default_sheet = oo.sheets.first
@@ -2511,12 +2570,12 @@ Sheet 3:
2511
2570
  assert_nil oo.last_column
2512
2571
  end
2513
2572
 
2514
- if false
2515
- # there is no google spreadsheet for this test
2516
- def test_bug_bbu_google
2517
- oo = Excel.new(key_of('bbu'))
2518
- assert_nothing_raised() {
2519
- assert_equal "File: test/bbu.xls
2573
+ if false
2574
+ # there is no google spreadsheet for this test
2575
+ def test_bug_bbu_google
2576
+ oo = Excel.new(key_of('bbu'))
2577
+ assert_nothing_raised() {
2578
+ assert_equal "File: test/bbu.xls
2520
2579
  Number of sheets: 3
2521
2580
  Sheets: 2007_12, Tabelle2, Tabelle3
2522
2581
  Sheet 1:
@@ -2528,21 +2587,21 @@ Sheet 2:
2528
2587
  - empty -
2529
2588
  Sheet 3:
2530
2589
  - empty -", oo.info
2531
- }
2590
+ }
2532
2591
 
2533
- oo.default_sheet = oo.sheets[1] # empty sheet
2534
- assert_nil oo.first_row
2535
- assert_nil oo.last_row
2536
- assert_nil oo.first_column
2537
- assert_nil oo.last_column
2538
- end
2539
- end # false
2592
+ oo.default_sheet = oo.sheets[1] # empty sheet
2593
+ assert_nil oo.first_row
2594
+ assert_nil oo.last_row
2595
+ assert_nil oo.first_column
2596
+ assert_nil oo.last_column
2597
+ end
2598
+ end # false
2540
2599
 
2541
- # def teardown
2542
- # puts "Options:"
2543
- # puts "OPENOFFICE = #{OPENOFFICE}"
2544
- # puts "EXCEL = #{EXCEL}"
2545
- # puts "GOOGLE = #{GOOGLE}"
2546
- # end
2600
+ # def teardown
2601
+ # puts "Options:"
2602
+ # puts "OPENOFFICE = #{OPENOFFICE}"
2603
+ # puts "EXCEL = #{EXCEL}"
2604
+ # puts "GOOGLE = #{GOOGLE}"
2605
+ # end
2547
2606
 
2548
2607
  end # class
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>roo</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/roo"; return false'>
35
35
  Get Version
36
- <a href="http://rubyforge.org/projects/roo" class="numbers">0.8.2</a>
36
+ <a href="http://rubyforge.org/projects/roo" class="numbers">0.8.3</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
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: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Preymesser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-28 00:00:00 +01:00
12
+ date: 2007-12-31 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency