Class: Spreadshoot::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadshoot.rb

Overview

Allows you to group cells to a logical table within a worksheet. Makes putting several tables to the same worksheet easier.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet, options = {}) ⇒ Table

Returns a new instance of Table.

See Also:



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/spreadshoot.rb', line 427

def initialize worksheet, options = {}
  @worksheet = worksheet
  @options = options
  @direction = options[:direction] || :vertical
  @row_index = 0
  @col_index = 0
  @row_max = 0
  @col_max = 0
  @row_topleft = options[:row_topleft] || @worksheet.row_index
  @col_topleft = options[:col_topleft] || @worksheet.col_index

  if tbl = options[:next_to]
    @row_topleft = tbl.row_topleft
    @col_topleft = tbl.col_topleft + tbl.col_max
  end
end

Instance Attribute Details

#col_indexObject

Returns the value of attribute col_index.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def col_index
  @col_index
end

#col_maxObject (readonly)

Returns the value of attribute col_max.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def col_max
  @col_max
end

#col_topleftObject (readonly)

Returns the value of attribute col_topleft.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def col_topleft
  @col_topleft
end

#directionObject (readonly)

Returns the value of attribute direction.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def direction
  @direction
end

#row_indexObject

Returns the value of attribute row_index.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def row_index
  @row_index
end

#row_maxObject (readonly)

Returns the value of attribute row_max.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def row_max
  @row_max
end

#row_topleftObject (readonly)

Returns the value of attribute row_topleft.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def row_topleft
  @row_topleft
end

#worksheetObject (readonly)

Returns the value of attribute worksheet.



423
424
425
# File 'lib/spreadshoot.rb', line 423

def worksheet
  @worksheet
end

Instance Method Details

#coordsObject

alphanumeric representation of coordinates



477
478
479
# File 'lib/spreadshoot.rb', line 477

def coords
  "#{Cell.alpha_index(current_col)}#{current_row+1}"
end

#current_colObject



472
473
474
# File 'lib/spreadshoot.rb', line 472

def current_col
  @col_topleft + @col_index
end

#current_rowObject



468
469
470
# File 'lib/spreadshoot.rb', line 468

def current_row
  @row_topleft + @row_index
end

#row(options = {}) {|row| ... } ⇒ Object

Yields:



454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/spreadshoot.rb', line 454

def row options = {}
  row = Row.new(self, options)
  yield(row) if block_given?

  if @direction == :vertical
    self.row_index += 1
    self.col_index = 0
  else
    self.col_index += 1
    self.row_index = 0
  end
  row
end