Class: WizRtf::Row
- Inherits:
-
Object
- Object
- WizRtf::Row
- Defined in:
- lib/wiz_rtf/row.rb
Instance Method Summary collapse
- #add_cell(cell, merge = false) ⇒ Object
- #column_width(offset) ⇒ Object
-
#initialize(table, cells = []) ⇒ Row
constructor
A new instance of Row.
- #render(io) ⇒ Object
- #row_spanned?(offset) ⇒ Boolean
Constructor Details
#initialize(table, cells = []) ⇒ Row
Returns a new instance of Row.
9 10 11 12 13 14 15 16 17 |
# File 'lib/wiz_rtf/row.rb', line 9 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wiz_rtf/row.rb', line 19 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
47 48 49 50 |
# File 'lib/wiz_rtf/row.rb', line 47 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wiz_rtf/row.rb', line 52 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
43 44 45 |
# File 'lib/wiz_rtf/row.rb', line 43 def row_spanned?(offset) @table.row_spans[offset] && @table.row_spans[offset].rowspan > 1 end |