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:



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/spreadshoot.rb', line 437

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.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def col_index
  @col_index
end

#col_maxObject (readonly)

Returns the value of attribute col_max.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def col_max
  @col_max
end

#col_topleftObject (readonly)

Returns the value of attribute col_topleft.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def col_topleft
  @col_topleft
end

#directionObject (readonly)

Returns the value of attribute direction.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def direction
  @direction
end

#row_indexObject

Returns the value of attribute row_index.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def row_index
  @row_index
end

#row_maxObject (readonly)

Returns the value of attribute row_max.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def row_max
  @row_max
end

#row_topleftObject (readonly)

Returns the value of attribute row_topleft.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def row_topleft
  @row_topleft
end

#worksheetObject (readonly)

Returns the value of attribute worksheet.



433
434
435
# File 'lib/spreadshoot.rb', line 433

def worksheet
  @worksheet
end

Instance Method Details

#coordsObject

alphanumeric representation of coordinates



491
492
493
# File 'lib/spreadshoot.rb', line 491

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

#current_colObject



486
487
488
# File 'lib/spreadshoot.rb', line 486

def current_col
  @col_topleft + @col_index
end

#current_rowObject



482
483
484
# File 'lib/spreadshoot.rb', line 482

def current_row
  @row_topleft + @row_index
end

#row(*args) {|row| ... } ⇒ Object

Yields:



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/spreadshoot.rb', line 464

def row *args
  options = args.last.is_a?(Hash) ? args.pop : {}
  row = Row.new(self, options)
  args.each do |cell_val|
    row.cell(cell_val, options)
  end
  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