Class: PureDocx::XmlGenerators::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/puredocx/xml_generators/table.rb

Constant Summary collapse

WITHOUT_BORDER_VALUES =
{ value: '',   default_value: 'single' }.freeze
BOLD_BORDER_VALUES =
{ value: '18', default_value: '4' }.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #rels_constructor

Instance Method Summary collapse

Methods inherited from Base

#xml

Constructor Details

#initialize(table_content, _rels_constructor, arguments = {}) ⇒ Table

Returns a new instance of Table.



13
14
15
16
17
18
19
20
21
22
# File 'lib/puredocx/xml_generators/table.rb', line 13

def initialize(table_content, _rels_constructor, arguments = {})
  @table_content        = table_content || []
  @columns_count        = table_content[0].size
  @received_table_width = arguments[:table_width]
  @received_col_width   = arguments[:col_width]
  ensure_columns_count!
  @sides_without_border = prepare_sides(WITHOUT_BORDER_VALUES, arguments[:sides_without_border])
  @bold_sides           = prepare_sides(BOLD_BORDER_VALUES,    arguments[:bold_sides])
  @paddings             = arguments[:paddings] || {}
end

Instance Attribute Details

#bold_sidesObject (readonly)

Returns the value of attribute bold_sides.



6
7
8
# File 'lib/puredocx/xml_generators/table.rb', line 6

def bold_sides
  @bold_sides
end

#columns_countObject (readonly)

Returns the value of attribute columns_count.



6
7
8
# File 'lib/puredocx/xml_generators/table.rb', line 6

def columns_count
  @columns_count
end

#received_col_widthObject (readonly)

Returns the value of attribute received_col_width.



6
7
8
# File 'lib/puredocx/xml_generators/table.rb', line 6

def received_col_width
  @received_col_width
end

#received_table_widthObject (readonly)

Returns the value of attribute received_table_width.



6
7
8
# File 'lib/puredocx/xml_generators/table.rb', line 6

def received_table_width
  @received_table_width
end

#sides_without_borderObject (readonly)

Returns the value of attribute sides_without_border.



6
7
8
# File 'lib/puredocx/xml_generators/table.rb', line 6

def sides_without_border
  @sides_without_border
end

#table_contentObject (readonly)

Returns the value of attribute table_content.



6
7
8
# File 'lib/puredocx/xml_generators/table.rb', line 6

def table_content
  @table_content
end

Instance Method Details

#paramsObject



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/puredocx/xml_generators/table.rb', line 28

def params
  {
    '{TABLE_WIDTH}'          => table_width,
    '{PADDING_TOP}'          => @paddings.fetch(:top,    0),
    '{PADDING_BOTTOM}'       => @paddings.fetch(:bottom, 0),
    '{PADDING_LEFT}'         => @paddings.fetch(:left,   0),
    '{PADDING_RIGHT}'        => @paddings.fetch(:right,  0),
    '{BORDER_TOP}'           => sides_without_border[:top],
    '{BORDER_BOTTOM}'        => sides_without_border[:bottom],
    '{BORDER_LEFT}'          => sides_without_border[:left],
    '{BORDER_RIGHT}'         => sides_without_border[:right],
    '{BORDER_INSIDE_H}'      => sides_without_border[:inside_h],
    '{BORDER_INSIDE_V}'      => sides_without_border[:inside_v],
    '{BORDER_TOP_SIZE}'      => bold_sides[:top],
    '{BORDER_BOTTOM_SIZE}'   => bold_sides[:bottom],
    '{BORDER_LEFT_SIZE}'     => bold_sides[:left],
    '{BORDER_RIGHT_SIZE}'    => bold_sides[:right],
    '{BORDER_INSIDE_H_SIZE}' => bold_sides[:inside_h],
    '{BORDER_INSIDE_V_SIZE}' => bold_sides[:inside_v],
    '{GRID_OPTIONS}'         => table_grid,
    '{ROWS}'                 => rows
  }
end

#templateObject



24
25
26
# File 'lib/puredocx/xml_generators/table.rb', line 24

def template
  File.read(DocArchive.template_path('table/table.xml'))
end