Class: Spreadshoot::Table
- Inherits:
-
Object
- Object
- Spreadshoot::Table
- 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
-
#col_index ⇒ Object
Returns the value of attribute col_index.
-
#col_max ⇒ Object
readonly
Returns the value of attribute col_max.
-
#col_topleft ⇒ Object
readonly
Returns the value of attribute col_topleft.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#row_index ⇒ Object
Returns the value of attribute row_index.
-
#row_max ⇒ Object
readonly
Returns the value of attribute row_max.
-
#row_topleft ⇒ Object
readonly
Returns the value of attribute row_topleft.
-
#worksheet ⇒ Object
readonly
Returns the value of attribute worksheet.
Instance Method Summary collapse
-
#coords ⇒ Object
alphanumeric representation of coordinates.
- #current_col ⇒ Object
- #current_row ⇒ Object
-
#initialize(worksheet, options = {}) ⇒ Table
constructor
A new instance of Table.
- #row(*args) {|row| ... } ⇒ Object
Constructor Details
#initialize(worksheet, options = {}) ⇒ Table
Returns a new instance of Table.
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, = {} @worksheet = worksheet = @direction = [:direction] || :vertical @row_index = 0 @col_index = 0 @row_max = 0 @col_max = 0 @row_topleft = [:row_topleft] || @worksheet.row_index @col_topleft = [:col_topleft] || @worksheet.col_index if tbl = [:next_to] @row_topleft = tbl.row_topleft @col_topleft = tbl.col_topleft + tbl.col_max end end |
Instance Attribute Details
#col_index ⇒ Object
Returns the value of attribute col_index.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def col_index @col_index end |
#col_max ⇒ Object (readonly)
Returns the value of attribute col_max.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def col_max @col_max end |
#col_topleft ⇒ Object (readonly)
Returns the value of attribute col_topleft.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def col_topleft @col_topleft end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def direction @direction end |
#row_index ⇒ Object
Returns the value of attribute row_index.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def row_index @row_index end |
#row_max ⇒ Object (readonly)
Returns the value of attribute row_max.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def row_max @row_max end |
#row_topleft ⇒ Object (readonly)
Returns the value of attribute row_topleft.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def row_topleft @row_topleft end |
#worksheet ⇒ Object (readonly)
Returns the value of attribute worksheet.
433 434 435 |
# File 'lib/spreadshoot.rb', line 433 def worksheet @worksheet end |
Instance Method Details
#coords ⇒ Object
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_col ⇒ Object
486 487 488 |
# File 'lib/spreadshoot.rb', line 486 def current_col @col_topleft + @col_index end |
#current_row ⇒ Object
482 483 484 |
# File 'lib/spreadshoot.rb', line 482 def current_row @row_topleft + @row_index end |
#row(*args) {|row| ... } ⇒ Object
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 = args.last.is_a?(Hash) ? args.pop : {} row = Row.new(self, ) args.each do |cell_val| row.cell(cell_val, ) 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 |