Class: WizRtf::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/wiz_rtf/table.rb

Constant Summary collapse

DEFAULT_COLUMN_WIDTH =
40

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows = [], options = {}, &block) ⇒ Table

Returns a new instance of Table.



12
13
14
15
16
17
18
19
20
# File 'lib/wiz_rtf/table.rb', line 12

def initialize(rows = [], options = {}, &block)
  @rows = []
  @row_spans = {}
  @column_widths = options[: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_widthsObject

Returns the value of attribute column_widths.



10
11
12
# File 'lib/wiz_rtf/table.rb', line 10

def column_widths
  @column_widths
end

#row_spansObject

Returns the value of attribute row_spans.



10
11
12
# File 'lib/wiz_rtf/table.rb', line 10

def row_spans
  @row_spans
end

Instance Method Details

#add_row(cells = []) ⇒ Object



22
23
24
# File 'lib/wiz_rtf/table.rb', line 22

def add_row(cells = [])
  @rows << WizRtf::Row.new(self, cells)
end

#render(io) ⇒ Object



26
27
28
29
30
# File 'lib/wiz_rtf/table.rb', line 26

def render(io)
  @rows.each do |row|
    row.render(io)
  end
end