Class: RRTF::TableCellNode
- Inherits:
-
CommandNode
- Object
- Node
- ContainerNode
- CommandNode
- RRTF::TableCellNode
- Defined in:
- lib/rrtf/node/table_cell_node.rb
Overview
This class represents a cell within an RTF table. The TableCellNode is a specialised command node that is forbidden from creating tables or having its parent changed.
Constant Summary
- DEFAULT_WIDTH =
A definition for the default width for the cell.
300
- TOP =
Top border
0
- RIGHT =
Right border
1
- BOTTOM =
Bottom border
2
- LEFT =
Left border
3
Instance Attribute Summary collapse
-
#shading_colour ⇒ Object
Attribute accessor.
-
#style ⇒ Object
Attribute accessor.
-
#width ⇒ Object
Width of cell.
Attributes inherited from CommandNode
#prefix, #split, #suffix, #wrap
Attributes inherited from ContainerNode
Attributes inherited from Node
Instance Method Summary collapse
-
#border_width=(width) ⇒ Object
This method assigns a width, in twips, for the borders on all sides of the cell.
-
#border_widths ⇒ Object
This method retrieves an array with the cell border width settings.
-
#bottom_border_width ⇒ Object
This method fetches the width for bottom border of a cell.
-
#bottom_border_width=(width) ⇒ Object
This method assigns a border width to the bottom side of a table cell.
-
#initialize(row, width = DEFAULT_WIDTH, style = nil, top = nil, right = nil, bottom = nil, left = nil) ⇒ TableCellNode
constructor
This is the constructor for the TableCellNode class.
-
#left_border_width ⇒ Object
This method fetches the width for left border of a cell.
-
#left_border_width=(width) ⇒ Object
This method assigns a border width to the left side of a table cell.
-
#paragraph(style = nil) ⇒ Object
This method overloads the paragraph method inherited from the ComamndNode class to forbid the creation of paragraphs.
-
#parent=(parent) ⇒ Object
This method overloads the parent= method inherited from the Node class to forbid the alteration of the cells parent.
-
#right_border_width ⇒ Object
This method fetches the width for right border of a cell.
-
#right_border_width=(width) ⇒ Object
This method assigns a border width to the right side of a table cell.
-
#table(rows, columns, *widths) ⇒ Object
This method overrides the table method inherited from CommandNode to forbid its use in table cells.
-
#to_rtf ⇒ Object
This method generates the RTF document text for a TableCellNode object.
-
#top_border_width ⇒ Object
This method fetches the width for top border of a cell.
-
#top_border_width=(width) ⇒ Object
This method assigns a border width to the top side of a table cell.
Methods inherited from CommandNode
#<<, #apply, #column_break, #footnote, #geometry, #image, #line_break, #link, #list, #section, #tab
Methods inherited from ContainerNode
#[], #each, #first, #last, #size, #store
Methods inherited from Node
#is_root?, #next_node, #previous_node, #root
Constructor Details
#initialize(row, width = DEFAULT_WIDTH, style = nil, top = nil, right = nil, bottom = nil, left = nil) ⇒ TableCellNode
This is the constructor for the TableCellNode class.
Parameters
- row
-
The row that the cell belongs to.
- width
-
The width to be assigned to the cell. This defaults to TableCellNode::DEFAULT_WIDTH.
- style
-
The style that is applied to the cell. This must be a ParagraphStyle class. Defaults to nil.
- top
-
The border width for the cells top border. Defaults to nil.
- right
-
The border width for the cells right hand border. Defaults to nil.
- bottom
-
The border width for the cells bottom border. Defaults to nil.
- left
-
The border width for the cells left hand border. Defaults to nil.
Exceptions
- RTFError
-
Generated whenever an invalid style setting is specified.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rrtf/node/table_cell_node.rb', line 38 def initialize(row, width=DEFAULT_WIDTH, style=nil, top=nil, right=nil, bottom=nil, left=nil) super(row, nil) if !style.nil? and !style.is_paragraph_style? RTFError.fire("Non-paragraph style specified for TableCellNode "\ "constructor.") end @width = (width != nil && width > 0) ? width : DEFAULT_WIDTH @borders = [(top != nil && top > 0) ? top : nil, (right != nil && right > 0) ? right : nil, (bottom != nil && bottom > 0) ? bottom : nil, (left != nil && left > 0) ? left : nil] @shading_colour = nil @style = style end |
Instance Attribute Details
#shading_colour ⇒ Object
Attribute accessor.
19 20 21 |
# File 'lib/rrtf/node/table_cell_node.rb', line 19 def shading_colour @shading_colour end |
#style ⇒ Object
Attribute accessor.
19 20 21 |
# File 'lib/rrtf/node/table_cell_node.rb', line 19 def style @style end |
#width ⇒ Object
Width of cell
17 18 19 |
# File 'lib/rrtf/node/table_cell_node.rb', line 17 def width @width end |
Instance Method Details
#border_width=(width) ⇒ Object
This method assigns a width, in twips, for the borders on all sides of the cell. Negative widths will be ignored and a width of zero will switch the border off.
Parameters
- width
-
The setting for the width of the border.
78 79 80 81 82 83 84 85 |
# File 'lib/rrtf/node/table_cell_node.rb', line 78 def border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[TOP] = @borders[RIGHT] = @borders[BOTTOM] = @borders[LEFT] = size.to_i else @borders = [nil, nil, nil, nil] end end |
#border_widths ⇒ Object
This method retrieves an array with the cell border width settings. The values are inserted in top, right, bottom, left order.
156 157 158 159 160 |
# File 'lib/rrtf/node/table_cell_node.rb', line 156 def border_widths widths = [] @borders.each {|entry| widths.push(entry.nil? ? 0 : entry)} widths end |
#bottom_border_width ⇒ Object
This method fetches the width for bottom border of a cell.
173 174 175 |
# File 'lib/rrtf/node/table_cell_node.rb', line 173 def bottom_border_width @borders[BOTTOM].nil? ? 0 : @borders[BOTTOM] end |
#bottom_border_width=(width) ⇒ Object
This method assigns a border width to the bottom side of a table cell. Negative values are ignored and a value of 0 switches the border off.
Parameters
- width
-
The new border width setting.
120 121 122 123 124 125 126 127 |
# File 'lib/rrtf/node/table_cell_node.rb', line 120 def bottom_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[BOTTOM] = size.to_i else @borders[BOTTOM] = nil end end |
#left_border_width ⇒ Object
This method fetches the width for left border of a cell.
178 179 180 |
# File 'lib/rrtf/node/table_cell_node.rb', line 178 def left_border_width @borders[LEFT].nil? ? 0 : @borders[LEFT] end |
#left_border_width=(width) ⇒ Object
This method assigns a border width to the left side of a table cell. Negative values are ignored and a value of 0 switches the border off.
Parameters
- width
-
The new border width setting.
134 135 136 137 138 139 140 141 |
# File 'lib/rrtf/node/table_cell_node.rb', line 134 def left_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[LEFT] = size.to_i else @borders[LEFT] = nil end end |
#paragraph(style = nil) ⇒ Object
This method overloads the paragraph method inherited from the ComamndNode class to forbid the creation of paragraphs.
Parameters
- style
-
The paragraph style, ignored
187 188 189 190 |
# File 'lib/rrtf/node/table_cell_node.rb', line 187 def paragraph(style=nil) RTFError.fire("TableCellNode#paragraph() called. Table cells cannot "\ "contain paragraphs.") 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.
197 198 199 |
# File 'lib/rrtf/node/table_cell_node.rb', line 197 def parent=(parent) RTFError.fire("Table cell nodes cannot have their parent changed.") end |
#right_border_width ⇒ Object
This method fetches the width for right border of a cell.
168 169 170 |
# File 'lib/rrtf/node/table_cell_node.rb', line 168 def right_border_width @borders[RIGHT].nil? ? 0 : @borders[RIGHT] end |
#right_border_width=(width) ⇒ Object
This method assigns a border width to the right side of a table cell. Negative values are ignored and a value of 0 switches the border off.
Parameters
- width
-
The new border width setting.
106 107 108 109 110 111 112 113 |
# File 'lib/rrtf/node/table_cell_node.rb', line 106 def right_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[RIGHT] = size.to_i else @borders[RIGHT] = nil end end |
#table(rows, columns, *widths) ⇒ Object
This method overrides the table method inherited from CommandNode to forbid its use in table cells.
Parameters
- rows
-
The number of rows for the table.
- columns
-
The number of columns for the table.
- *widths
-
One or more integers representing the widths for the table columns.
209 210 211 |
# File 'lib/rrtf/node/table_cell_node.rb', line 209 def table(rows, columns, *widths) RTFError.fire("TableCellNode#table() called. Nested tables not allowed.") end |
#to_rtf ⇒ Object
This method generates the RTF document text for a TableCellNode object.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/rrtf/node/table_cell_node.rb', line 214 def to_rtf text = StringIO.new separator = split? ? "\n" : " " line = (separator == " ") text << "\\pard\\intbl" text << @style.prefix(root) if @style != nil text << separator self.each do |entry| text << "\n" if line line = true text << entry.to_rtf end text << (split? ? "\n" : " ") text << "\\cell" text.string end |
#top_border_width ⇒ Object
This method fetches the width for top border of a cell.
163 164 165 |
# File 'lib/rrtf/node/table_cell_node.rb', line 163 def top_border_width @borders[TOP].nil? ? 0 : @borders[TOP] end |
#top_border_width=(width) ⇒ Object
This method assigns a border width to the top side of a table cell. Negative values are ignored and a value of 0 switches the border off.
Parameters
- width
-
The new border width setting.
92 93 94 95 96 97 98 99 |
# File 'lib/rrtf/node/table_cell_node.rb', line 92 def top_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[TOP] = size.to_i else @borders[TOP] = nil end end |