Class: WizRtf::Row
- Inherits:
-
Object
- Object
- WizRtf::Row
- Defined in:
- lib/wiz_rtf/row.rb
Overview
Represents a table row.
Instance Method Summary collapse
-
#add_cell(cell, merge = false) ⇒ Object
add a Cell object to the Cells array.
- #column_width(offset) ⇒ Object
-
#initialize(table, cells = []) ⇒ Row
constructor
This is the constructor for the Row class.
-
#render(io) ⇒ Object
Outputs the Partial Rtf Document to a Generic Stream as a Rich Text Format (RTF).
- #row_spanned?(offset) ⇒ Boolean
Constructor Details
#initialize(table, cells = []) ⇒ Row
This is the constructor for the Row class.
-
table
- A reference to table that owns the row. -
cells
- The number of cells that the row will contain.
15 16 17 18 19 20 21 22 23 |
# File 'lib/wiz_rtf/row.rb', line 15 def initialize(table, cells = []) @table = table @cells = [] @col_offset = 1 @right_width = 0 cells.each do |cell| add_cell cell end end |
Instance Method Details
#add_cell(cell, merge = false) ⇒ Object
add a Cell object to the Cells array.
-
cell
- a Cell object. -
merge
- is merges the specified table cells.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wiz_rtf/row.rb', line 28 def add_cell(cell, merge = false) add_cell('', true) if !merge && row_spanned?(@col_offset) c = WizRtf::Cell.new(cell) @table.row_spans[@col_offset] = c if c.rowspan > 1 if c.rowspan > 1 c.v_merge = :clvmgf elsif row_spanned? @col_offset c.v_merge = :clvmrg @table.row_spans[@col_offset].rowspan -= 1 c.colspan = @table.row_spans[@col_offset].colspan || c.colspan end c.colspan.times do @right_width += column_width(@col_offset) @col_offset += 1 end c.right_width = @right_width @cells << c add_cell('', true) if row_spanned?(@col_offset) end |
#column_width(offset) ⇒ Object
56 57 58 59 |
# File 'lib/wiz_rtf/row.rb', line 56 def column_width(offset) return 20 * (@table.column_widths[offset] || WizRtf::Table::DEFAULT_COLUMN_WIDTH) if @table.column_widths.is_a?(Hash) @table.column_widths * 20 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/wiz_rtf/row.rb', line 63 def render(io) io.cmd :trowd io.cmd :trbrdrt io.cmd :brdrs io.cmd :brdrw10 io.cmd :trbrdrl io.cmd :brdrs io.cmd :brdrw10 io.cmd :trbrdrb io.cmd :brdrs io.cmd :brdrw10 io.cmd :trbrdrr io.cmd :brdrs io.cmd :brdrw10 io.cmd :trautofit1 io.cmd :intbl @cells.each do |c| c.render(io) end io.cmd :row end |
#row_spanned?(offset) ⇒ Boolean
52 53 54 |
# File 'lib/wiz_rtf/row.rb', line 52 def row_spanned?(offset) @table.row_spans[offset] && @table.row_spans[offset].rowspan > 1 end |