Class: RTF::TableRowNode
- Inherits:
-
ContainerNode
- Object
- Node
- ContainerNode
- RTF::TableRowNode
- Defined in:
- lib/rtf/node.rb
Overview
This class represents a row within an RTF table. The TableRowNode is a specialised container node that can hold only TableCellNodes and, once created, cannot be resized. Its also not possible to change the parent of a TableRowNode object.
Instance Attribute Summary
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 row.
-
#initialize(table, cells, *widths) ⇒ TableRowNode
constructor
This is the constructor for the TableRowNode class.
-
#length ⇒ Object
Attribute accessors.
-
#parent=(parent) ⇒ Object
This method overloads the parent= method inherited from the Node class to forbid the alteration of the cells parent.
-
#shading_colour=(colour) ⇒ Object
This method sets the shading colour for a row.
-
#to_rtf ⇒ Object
This method generates the RTF document text for a TableCellNode object.
Methods inherited from ContainerNode
#[], #each, #first, #last, #size, #store
Methods inherited from Node
#is_root?, #next_node, #previous_node, #root
Constructor Details
#initialize(table, cells, *widths) ⇒ TableRowNode
This is the constructor for the TableRowNode class.
Parameters
- table
-
A reference to table that owns the row.
- cells
-
The number of cells that the row will contain.
- widths
-
One or more integers specifying the widths for the table columns
853 854 855 856 857 858 859 860 861 |
# File 'lib/rtf/node.rb', line 853 def initialize(table, cells, *widths) super(table) do entries = [] cells.times do |index| entries.push(TableCellNode.new(self, widths[index])) end entries end 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 row.
Parameters
- width
-
The border width setting to apply. Negative values are ignored and zero switches the border off.
874 875 876 |
# File 'lib/rtf/node.rb', line 874 def border_width=(width) self.each {|cell| cell.border_width = width} end |
#length ⇒ Object
Attribute accessors
864 865 866 |
# File 'lib/rtf/node.rb', line 864 def length entries.size end |
#parent=(parent) ⇒ Object
This method overloads the parent= method inherited from the Node class to forbid the alteration of the cells parent.
Parameters
- parent
-
A reference to the new node parent.
883 884 885 |
# File 'lib/rtf/node.rb', line 883 def parent=(parent) RTFError.fire("Table row nodes cannot have their parent changed.") end |
#shading_colour=(colour) ⇒ Object
This method sets the shading colour for a row.
Parameters
- colour
-
A reference to the Colour object that represents the new shading colour. Set to nil to switch shading off.
892 893 894 |
# File 'lib/rtf/node.rb', line 892 def shading_colour=(colour) self.each {|cell| cell.shading_colour = colour} end |
#to_rtf ⇒ Object
This method generates the RTF document text for a TableCellNode object.
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 |
# File 'lib/rtf/node.rb', line 906 def to_rtf text = StringIO.new temp = StringIO.new offset = 0 text << "\\trowd\\tgraph#{parent.cell_margin}" self.each do |entry| widths = entry.border_widths colour = entry.shading_colour text << "\n" text << "\\clbrdrt\\brdrw#{widths[0]}\\brdrs" if widths[0] != 0 text << "\\clbrdrl\\brdrw#{widths[3]}\\brdrs" if widths[3] != 0 text << "\\clbrdrb\\brdrw#{widths[2]}\\brdrs" if widths[2] != 0 text << "\\clbrdrr\\brdrw#{widths[1]}\\brdrs" if widths[1] != 0 text << "\\clcbpat#{root.colours.index(colour)}" if colour != nil text << "\\cellx#{entry.width + offset}" temp << "\n#{entry.to_rtf}" offset += entry.width end text << "#{temp.string}\n\\row" text.string end |