Class: ODDB::Text::Table

Inherits:
Object show all
Defined in:
src/model/text.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Table) initialize(*args)

A new instance of Table



285
286
287
288
# File 'src/model/text.rb', line 285

def initialize(*args)
  super
  @rows = []
end

Instance Attribute Details

- (Object) rows (readonly)

Returns the value of attribute rows



284
285
286
# File 'src/model/text.rb', line 284

def rows
  @rows
end

Instance Method Details

- (Object) <<(str)



387
388
389
# File 'src/model/text.rb', line 387

def <<(str)
  current_cell << str
end

- (Object) cell(row, cell)



289
290
291
# File 'src/model/text.rb', line 289

def cell(row, cell)
  @rows[row][cell]
end

- (Object) clean!



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'src/model/text.rb', line 292

def clean!
  @rows.each { |row|
    while((cell = row.last) && cell.empty?)
      row.pop
    end
  }
  while((row = @rows.last) && row.empty?)
    @rows.pop
  end
  @rows.each do |row|
    row.each do |cell|
      cell.clean!
    end
  end
end

- (Object) column_widths



307
308
309
310
311
312
313
314
315
316
# File 'src/model/text.rb', line 307

def column_widths
  @rows.inject([]) { |memo, row|
    row.each_with_index { |cell, idx|
      lens = cell.to_s.split("\n").collect { |part| part.length }
      candidate = lens.max.to_i / cell.col_span
      memo[idx] = [memo[idx].to_i, candidate].max
    }
    memo
  }
end

- (Object) current_cell



317
318
319
# File 'src/model/text.rb', line 317

def current_cell
  current_row.last rescue nil
end

- (Object) current_row



320
321
322
# File 'src/model/text.rb', line 320

def current_row
  @rows.last rescue nil
end

- (Object) each_normalized(&block)



346
347
348
349
350
351
# File 'src/model/text.rb', line 346

def each_normalized(&block)
  wd = width
  @rows.each { |row|
    block.call(row + Array.new(wd - row.length))
  }
end

- (Boolean) empty?

Returns:

  • (Boolean)


323
324
325
# File 'src/model/text.rb', line 323

def empty?
  @rows.flatten.all? { |cell| cell.strip.empty? }
end

- (Object) gsub!(*args, &gsub)



326
327
328
329
330
331
332
# File 'src/model/text.rb', line 326

def gsub! *args, &gsub
  @rows.each do |row|
    row.each do |cell|
      cell.gsub! *args, &gsub
    end
  end
end

- (Object) next_cell!



333
334
335
336
337
# File 'src/model/text.rb', line 333

def next_cell!
  cell = Cell.new
  @rows.last.push cell
  cell
end

- (Object) next_paragraph



338
339
340
# File 'src/model/text.rb', line 338

def next_paragraph
  current_cell << "\n" if current_cell
end

- (Object) next_row!



341
342
343
344
345
# File 'src/model/text.rb', line 341

def next_row!
  row = []
  @rows.push row
  row
end

- (Boolean) preformatted?

Returns:

  • (Boolean)


352
353
354
# File 'src/model/text.rb', line 352

def preformatted?
  true
end

- (Object) to_s(opts = {})



355
# File 'src/model/text.rb', line 355

def to_s opts={}

- (Object) width



384
385
386
# File 'src/model/text.rb', line 384

def width
  @rows.collect { |row| row.length }.max  
end

- (Object) wrap(str, width, opts = {})



390
# File 'src/model/text.rb', line 390

def wrap str, width, opts={}