Class: WizRtf::Table
- Inherits:
-
Object
- Object
- WizRtf::Table
- Defined in:
- lib/wiz_rtf/table.rb
Overview
the Rtf Document Table.
Constant Summary collapse
- DEFAULT_COLUMN_WIDTH =
40
Instance Attribute Summary collapse
-
#column_widths ⇒ Object
Returns the value of attribute column_widths.
-
#row_spans ⇒ Object
Returns the value of attribute row_spans.
Instance Method Summary collapse
-
#add_row(cells = []) ⇒ Object
Add The Cells Array of the Row.
-
#initialize(rows = [], options = {}, &block) ⇒ Table
constructor
Creates a new Table *
rows
- a table can be thought of as consisting of rows and columns. -
#render(io) ⇒ Object
Outputs the Partial Rtf Document to a Generic Stream as a Rich Text Format (RTF).
Constructor Details
#initialize(rows = [], options = {}, &block) ⇒ Table
Creates a new Table
-
rows
- a table can be thought of as consisting of rows and columns.
Options:
-
column_widths
- sets the widths of the Columns.
Example:
WizRtf::Table.new([
[{content: WizRtf::Image.new('h:\eahey.png'),rowspan:4},{content:'4',rowspan:4},1,{content:'1',colspan:2}],
[{content:'4',rowspan:3,colspan:2},8],[11]
], column_widths:{1=>100,2 => 100,3 => 50,4 => 50,5 => 50}) do
add_row [1]
end
26 27 28 29 30 31 32 33 34 |
# File 'lib/wiz_rtf/table.rb', line 26 def initialize(rows = [], = {}, &block) @rows = [] @row_spans = {} @column_widths = [:column_widths] || DEFAULT_COLUMN_WIDTH rows.each_index do |index| add_row rows[index] end block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given? end |
Instance Attribute Details
#column_widths ⇒ Object
Returns the value of attribute column_widths.
11 12 13 |
# File 'lib/wiz_rtf/table.rb', line 11 def column_widths @column_widths end |
#row_spans ⇒ Object
Returns the value of attribute row_spans.
11 12 13 |
# File 'lib/wiz_rtf/table.rb', line 11 def row_spans @row_spans end |
Instance Method Details
#add_row(cells = []) ⇒ Object
Add The Cells Array of the Row.
-
cells
- the cells array.
Example:
add_row [content:‘4’,rowspan:3,colspan:2,8]
42 43 44 |
# File 'lib/wiz_rtf/table.rb', line 42 def add_row(cells = []) @rows << WizRtf::Row.new(self, cells) end |
#render(io) ⇒ Object
Outputs the Partial Rtf Document to a Generic Stream as a Rich Text Format (RTF).
-
io
- The Generic IO to Output the RTF Document.
48 49 50 51 52 |
# File 'lib/wiz_rtf/table.rb', line 48 def render(io) @rows.each do |row| row.render(io) end end |