roo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,15 @@ require 'fileutils'
6
6
  require 'zip/zipfilesystem'
7
7
  require 'date'
8
8
 
9
+ class Fixnum
10
+ def as_letter
11
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[self-1,1]
12
+ end
13
+ end
14
+
9
15
  class Openoffice
10
16
 
17
+
11
18
  def initialize(filename)
12
19
  @cells_read = false
13
20
  @filename = filename
@@ -41,7 +48,7 @@ class Openoffice
41
48
  end
42
49
  end
43
50
  if col.class == String
44
- col = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(col.upcase)+1
51
+ col = Openoffice.letter_to_number(col)
45
52
  end
46
53
  read_cells unless @cells_read
47
54
  @cell["#{row},#{col}"]
@@ -167,6 +174,18 @@ class Openoffice
167
174
  number_to_letter(last_column)
168
175
  end
169
176
 
177
+ def first_row_as_letter
178
+ number_to_letter(first_row)
179
+ end
180
+
181
+ def last_row_as_letter
182
+ number_to_letter(last_row)
183
+ end
184
+
185
+ def as_letter(n)
186
+ number_to_letter(last_row)
187
+ end
188
+
170
189
  private
171
190
 
172
191
  def number_to_letter(n)
@@ -240,27 +259,19 @@ private
240
259
  x = 1
241
260
  end
242
261
  end
243
- # p se.attributes['name']
244
- # return_sheets << se.attributes['name']
245
- end # richtiges sheet
262
+ end # sheet
246
263
  end
247
264
  end
248
265
  end
249
266
  end
250
267
  end
251
268
  end
252
- # puts oo_element_count.to_s+" oo_element_count "
253
269
  end
254
- # puts oo_document_count.to_s+" oo_document_count "
255
- # p @cell
256
270
  @cells_read = true
257
271
  end
258
272
 
259
273
  def process_zipfile(zip, path='')
260
274
  if zip.file.file? path
261
- # puts %{#{path}: "#{zip.read(path)}"}
262
- # puts %{#{path}:}
263
-
264
275
  if path == "content.xml"
265
276
  open(@tmpdir+'/'+'roo_content.xml','w') {|f|
266
277
  f << zip.read(path)
@@ -269,7 +280,6 @@ private
269
280
  else
270
281
  unless path.empty?
271
282
  path += '/'
272
- # puts path
273
283
  end
274
284
  zip.dir.foreach(path) do |filename|
275
285
  process_zipfile(zip, path+filename)
@@ -283,5 +293,16 @@ private
283
293
  process_zipfile(zip)
284
294
  end
285
295
  end
296
+
297
+ def Openoffice.letter_to_number(letters)
298
+ result = 0
299
+ while letters && letters.length > 0
300
+ character = letters[0,1].upcase
301
+ num = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(character)+1
302
+ result = result * 26 + num
303
+ letters = letters[1..-1]
304
+ end
305
+ result
306
+ end
286
307
 
287
308
  end
@@ -2,7 +2,7 @@ module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -2,6 +2,14 @@ require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestRoo < Test::Unit::TestCase
4
4
 
5
+ def test_letters
6
+ assert_equal 1, Openoffice.letter_to_number('A')
7
+ assert_equal 1, Openoffice.letter_to_number('a')
8
+ assert_equal 2, Openoffice.letter_to_number('B')
9
+ assert_equal 26, Openoffice.letter_to_number('Z')
10
+ assert_equal 27, Openoffice.letter_to_number('AA')
11
+ end
12
+
5
13
  def test_sheets
6
14
  oo = Openoffice.new("test/numbers1.ods")
7
15
  assert_equal ["Tabelle1","Name of Sheet 2","Sheet3"], oo.sheets
@@ -121,11 +129,23 @@ class TestRoo < Test::Unit::TestCase
121
129
  def test_boundaries
122
130
  oo = Openoffice.new("test/numbers1.ods")
123
131
  oo.default_sheet = "Name of Sheet 2"
124
- assert true
125
132
  assert_equal 2, oo.first_column
126
133
  assert_equal 'B', oo.first_column_as_letter
127
134
  assert_equal 5, oo.first_row
128
135
  assert_equal 'E', oo.last_column_as_letter
129
136
  assert_equal 14, oo.last_row
137
+ assert_equal 'E', oo.first_row_as_letter
138
+ assert_equal 'N', oo.last_row_as_letter
139
+ assert_equal 'N', oo.last_row.as_letter
140
+ end
141
+
142
+ def test_multiple_letters
143
+ oo = Openoffice.new("test/numbers1.ods")
144
+ oo.default_sheet = "Sheet3"
145
+ assert_equal "i am AA", oo.cell('AA',1)
146
+ assert_equal "i am AB", oo.cell('AB',1)
147
+ assert_equal "i am BA", oo.cell('BA',1)
148
+ assert_equal "i am BA", oo.cell(1,'BA')
149
+
130
150
  end
131
151
  end
@@ -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.1.1</a>
36
+ <a href="http://rubyforge.org/projects/roo" class="numbers">0.1.2</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
@@ -120,6 +120,32 @@
120
120
  2007-05-18 3.0 370.35 G��stebuch
121
121
  2007-05-18 1.75 216.0375 G��stebuch
122
122
  </code>
123
+ </pre>
124
+
125
+ <p>With the newly written methods</p>
126
+
127
+
128
+ <code>first_column</code>,
129
+ <code>last_column</code>,
130
+ <code>first_row</code> and
131
+ <code>last_row</code>
132
+
133
+ <p>you can change line 8 from</p>
134
+
135
+
136
+ <pre>
137
+ <code>
138
+ 8 4.upto(1000) do |line|
139
+ </code>
140
+ </pre>
141
+
142
+ <p>to</p>
143
+
144
+
145
+ <pre>
146
+ <code>
147
+ 8 4.upto(oo.last_row) do |line|
148
+ </code>
123
149
  </pre>
124
150
 
125
151
  <h2>Documentation</h2>
@@ -151,7 +177,7 @@
151
177
 
152
178
  <p>Comments are welcome. Send an email to <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>.</p>
153
179
  <p class="coda">
154
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 30th May 2007<br>
180
+ <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 31st May 2007<br>
155
181
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
156
182
  </p>
157
183
  </div>
@@ -75,6 +75,29 @@ which produces this output
75
75
  </code>
76
76
  </pre>
77
77
 
78
+ With the newly written methods
79
+
80
+ <code>first_column</code>,
81
+ <code>last_column</code>,
82
+ <code>first_row</code> and
83
+ <code>last_row</code>
84
+
85
+ you can change line 8 from
86
+
87
+ <pre>
88
+ <code>
89
+ 8 4.upto(1000) do |line|
90
+ </code>
91
+ </pre>
92
+
93
+ to
94
+
95
+ <pre>
96
+ <code>
97
+ 8 4.upto(oo.last_row) do |line|
98
+ </code>
99
+ </pre>
100
+
78
101
  h2. Documentation
79
102
 
80
103
  "rdoc":rdoc/index.html
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: roo
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
6
+ version: 0.1.2
7
7
  date: 2007-05-31 00:00:00 +02:00
8
8
  summary: roo can access the contents of OpenOffice-Spreadsheets
9
9
  require_paths: