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

Constructor Details

#initialize(model = nil) ⇒ TableBuilder

Returns a new instance of TableBuilder.



22
23
24
25
# File 'lib/uniword/builder/table_builder.rb', line 22

def initialize(model = nil)
  super
  ensure_table_structure
end

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



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

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

#indent(value) ⇒ Object



43
44
45
46
47
48
# File 'lib/uniword/builder/table_builder.rb', line 43

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

#row {|r| ... } ⇒ Object

Yields:

  • (r)


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

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

#width(value, rule: nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/uniword/builder/table_builder.rb', line 35

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