Class: OxmlMaker::Table

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

Overview

Table class represents a table in an OXML document. Initialized with a hash containing :columns, :rows, :data, and :font_size.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Table

Returns a new instance of Table.



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

def initialize(table)
  @table = table
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



8
9
10
# File 'lib/oxml_maker/table.rb', line 8

def table
  @table
end

Instance Method Details

#templateObject



14
15
16
17
18
19
20
21
22
23
24
25
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
# File 'lib/oxml_maker/table.rb', line 14

def template
  <<~XML
    <w:tbl>
      <w:tblPr>
        <w:tblStyle w:val="DefaultTable"/>
        <w:tblW w:w="10468" w:type="dxa"/>
        <w:tblInd w:w="0" w:type="dxa"/>
        <w:tblBorders>
          <w:top w:color="666666" w:val="single" w:sz="4" w:space="0"/>
          <w:left w:color="666666" w:val="single" w:sz="4" w:space="0"/>
          <w:bottom w:color="666666" w:val="single" w:sz="4" w:space="0"/>
          <w:right w:color="666666" w:val="single" w:sz="4" w:space="0"/>
          <w:insideH w:color="666666" w:val="single" w:sz="4" w:space="0"/>
          <w:insideV w:color="666666" w:val="single" w:sz="4" w:space="0"/>
        </w:tblBorders>
        <w:tblLayout w:type="fixed"/>
        <w:tblLook w:val="0600"/>
      </w:tblPr>
      <w:tblGrid>
        #{table[:columns].map { |col| grid_col(col) }.join("\n")}
      </w:tblGrid>
      <w:tr>
        <w:tblPrEx>
          <w:tblCellMar>
            <w:top w:w="0" w:type="dxa"/>
            <w:bottom w:w="0" w:type="dxa"/>
          </w:tblCellMar>
        </w:tblPrEx>
        <w:trPr>
          <w:tblAlign w:val="center"/>
        </w:trPr>
        #{table[:columns].map { |column| header_row(column) }.join("\n")}
      </w:tr>
      #{table[:data].map { |_k, data| body_row(data) }.flatten.join("\n")}
    </w:tbl>
  XML
end