Class: RTF::TableNode
- Inherits:
-
ContainerNode
- Object
- Node
- ContainerNode
- RTF::TableNode
- Defined in:
- lib/rtf/node.rb
Overview
This class represents a table node within an RTF document. Table nodes are specialised container nodes that contain only TableRowNodes and have their size specified when they are created an cannot be resized after that.
Instance Attribute Summary collapse
-
#cell_margin ⇒ Object
Attribute accessor.
Attributes inherited from ContainerNode
Attributes inherited from Node
Instance Method Summary collapse
-
#border_width=(width) ⇒ Object
This method assigns a border width setting to all of the sides on all of the cells within a table.
-
#column_shading_colour(index, colour) ⇒ Object
(also: #column_shading_color)
This method assigns a shading colour to a specified column within a TableNode object.
-
#columns ⇒ Object
Attribute accessor.
-
#initialize(parent, rows, columns, *widths) ⇒ TableNode
constructor
This is a constructor for the TableNode class.
-
#row_shading_colour(index, colour) ⇒ Object
(also: #row_shading_color)
This method assigns a shading colour to a specified row within a TableNode object.
-
#rows ⇒ Object
Attribute accessor.
-
#shading_colour(colour) ⇒ Object
(also: #shading_color)
This method provides a means of assigning a shading colour to a selection of cells within a table.
-
#store(node) ⇒ Object
This method overloads the store method inherited from the ContainerNode class to forbid addition of further nodes.
-
#to_rtf ⇒ Object
This method generates the RTF document text for a TableCellNode object.
Methods inherited from ContainerNode
#[], #each, #first, #last, #size
Methods inherited from Node
#is_root?, #next_node, #previous_node, #root
Constructor Details
#initialize(parent, rows, columns, *widths) ⇒ TableNode
This is a constructor for the TableNode class.
Parameters
- parent
-
A reference to the node that owns the table.
- rows
-
The number of rows in the tabkle.
- columns
-
The number of columns in the table.
- *widths
-
One or more integers specifying the widths of the table columns.
539 540 541 542 543 544 545 546 |
# File 'lib/rtf/node.rb', line 539 def initialize(parent, rows, columns, *widths) super(parent) do entries = [] rows.times {entries.push(TableRowNode.new(self, columns, *widths))} entries end @cell_margin = 100 end |
Instance Attribute Details
#cell_margin ⇒ Object
Attribute accessor.
526 527 528 |
# File 'lib/rtf/node.rb', line 526 def cell_margin @cell_margin end |
Instance Method Details
#border_width=(width) ⇒ Object
This method assigns a border width setting to all of the sides on all of the cells within a table.
Parameters
- width
-
The border width setting to apply. Negative values are ignored and zero switches the border off.
564 565 566 |
# File 'lib/rtf/node.rb', line 564 def border_width=(width) self.each {|row| row.border_width = width} end |
#column_shading_colour(index, colour) ⇒ Object Also known as: column_shading_color
This method assigns a shading colour to a specified column within a TableNode object.
Parameters
- index
-
The offset from the first column of the column to have shading applied to it.
- colour
-
A reference to a Colour object representing the shading colour to be used. Set to nil to clear shading.
589 590 591 592 593 594 |
# File 'lib/rtf/node.rb', line 589 def column_shading_colour(index, colour) self.each do |row| cell = row[index] cell.shading_colour = colour if cell != nil end end |
#columns ⇒ Object
Attribute accessor.
554 555 556 |
# File 'lib/rtf/node.rb', line 554 def columns entries[0].length end |
#row_shading_colour(index, colour) ⇒ Object Also known as: row_shading_color
This method assigns a shading colour to a specified row within a TableNode object.
Parameters
- index
-
The offset from the first row of the row to have shading applied to it.
- colour
-
A reference to a Colour object representing the shading colour to be used. Set to nil to clear shading.
576 577 578 579 |
# File 'lib/rtf/node.rb', line 576 def row_shading_colour(index, colour) row = self[index] row.shading_colour = colour if row != nil end |
#rows ⇒ Object
Attribute accessor.
549 550 551 |
# File 'lib/rtf/node.rb', line 549 def rows entries.size end |
#shading_colour(colour) ⇒ Object Also known as: shading_color
This method provides a means of assigning a shading colour to a selection of cells within a table. The method accepts a block that takes three parameters - a TableCellNode representing a cell within the table, an integer representing the x offset of the cell and an integer representing the y offset of the cell. If the block returns true then shading will be applied to the cell.
Parameters
- colour
-
A reference to a Colour object representing the shading colour to be applied. Set to nil to remove shading.
606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/rtf/node.rb', line 606 def shading_colour(colour) if block_given? 0.upto(self.size - 1) do |x| row = self[x] 0.upto(row.size - 1) do |y| apply = yield row[y], x, y row[y].shading_colour = colour if apply end end end end |
#store(node) ⇒ Object
This method overloads the store method inherited from the ContainerNode class to forbid addition of further nodes.
Parameters
- node
-
A reference to the node to be added.
623 624 625 |
# File 'lib/rtf/node.rb', line 623 def store(node) RTFError.fire("Table nodes cannot have nodes added to.") end |
#to_rtf ⇒ Object
This method generates the RTF document text for a TableCellNode object.
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/rtf/node.rb', line 628 def to_rtf text = StringIO.new size = 0 self.each do |row| if size > 0 text << "\n" else size = 1 end text << row.to_rtf end text.string end |