Class: Uniword::Builder::TableBuilder

Inherits:
BaseBuilder show all
Includes:
HasBorders, HasShading
Defined in:
lib/uniword/builder/table_builder.rb

Overview

Builds and configures Table objects.

Examples:

Create a table

doc.table do |t|
  t.row do |r|
    r.cell(text: 'Name')
    r.cell(text: 'Value')
  end
end

Instance Attribute Summary

Attributes inherited from BaseBuilder

#model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasShading

#shading

Methods included from HasBorders

#borders

Methods inherited from BaseBuilder

#build, from_model, #initialize

Constructor Details

This class inherits a constructor from Uniword::Builder::BaseBuilder

Class Method Details

.default_model_classObject



18
19
20
# File 'lib/uniword/builder/table_builder.rb', line 18

def self.default_model_class
  Wordprocessingml::Table
end

Instance Method Details

#align=(value) ⇒ Object



57
58
59
60
61
# File 'lib/uniword/builder/table_builder.rb', line 57

def align=(value)
  ensure_properties
  @model.properties.justification = Properties::TableJustification.new(value: value.to_s)
  self
end

#indent(value) ⇒ self

Set table indentation

Parameters:

  • value (Integer)

    Indent in twips

Returns:

  • (self)


50
51
52
53
54
55
# File 'lib/uniword/builder/table_builder.rb', line 50

def indent(value)
  ensure_properties
  @model.properties.table_indent ||= Properties::TableIndent.new
  @model.properties.table_indent.value = value
  self
end

#row {|TableRowBuilder| ... } ⇒ TableRowBuilder

Create and add a row to the table

Yields:

Returns:



26
27
28
29
30
31
# File 'lib/uniword/builder/table_builder.rb', line 26

def row(&block)
  r = TableRowBuilder.new
  yield(r) if block
  @model.rows << r.build
  r
end

#width(value, rule: nil) ⇒ self

Set table width

Parameters:

  • value (Integer)

    Width in twips

  • rule (String) (defaults to: nil)

    Width rule (‘auto’, ‘exact’, ‘pct’)

Returns:

  • (self)


38
39
40
41
42
43
44
# File 'lib/uniword/builder/table_builder.rb', line 38

def width(value, rule: nil)
  ensure_properties
  @model.properties.table_width ||= Properties::TableWidth.new
  @model.properties.table_width.value = value
  @model.properties.table_width.rule = rule if rule
  self
end