Class: Docxer::Word::Contents::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/docxer/word/contents/table.rb

Defined Under Namespace

Classes: TableRow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Table

Returns a new instance of Table.



8
9
10
11
12
13
14
15
16
17
# File 'lib/docxer/word/contents/table.rb', line 8

def initialize(options={})
  @options = options
  @rows = []

  if block_given?
    yield self
  else

  end
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/docxer/word/contents/table.rb', line 7

def options
  @options
end

#rowsObject

Returns the value of attribute rows.



7
8
9
# File 'lib/docxer/word/contents/table.rb', line 7

def rows
  @rows
end

Instance Method Details

#render(xml) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/docxer/word/contents/table.rb', line 26

def render(xml)
  xml['w'].tbl do
    xml['w'].tblPr do
      xml['w'].tblStyle( 'w:val' => options[:style] ) if options[:style]
      xml['w'].tblW( 'w:w' => options[:width], 'w:type' => "auto" ) if options[:width]
      xml['w'].tblLook( 'w:val' => "04A0", 'w:firstRow' => 1, 'w:lastRow' => 0, 'w:firstColumn' => 1, 'w:lastColumn' => 0, 'w:noHBand' => 0, 'w:noVBand' => 1 )
      if @options[:borders]
        xml['w'].tblBorders do
          @options[:borders].each do |k, v|
            if v.nil?
              xml['w'].send(k, 'w:val' => "none", 'w:sz' => "0", 'w:space' => "0", 'w:color' => "auto" )
            else
              xml['w'].send(k, 'w:val' => "none", 'w:sz' => v, 'w:space' => "0", 'w:color' => "auto" )
            end
          end
        end
      end
    end
    xml['w'].tblGrid do
      if options[:columns_width]
        options[:columns_width].each do |width|
          xml['w'].gridCol( 'w:w' => width.to_i * 14.92 )
        end
      end
    end
    @rows.each do |row|
      row.render(xml)
    end
  end
end

#tr(options = {}, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/docxer/word/contents/table.rb', line 19

def tr(options={}, &block)
  options = @options.merge(options)
  row = TableRow.new(options, &block)
  @rows << row
  row
end