Class: Uniword::Builder::TableCellBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- Uniword::Builder::TableCellBuilder
- Includes:
- HasBorders, HasShading
- Defined in:
- lib/uniword/builder/table_cell_builder.rb
Overview
Builds and configures TableCell objects.
Instance Attribute Summary
Attributes inherited from BaseBuilder
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(element) ⇒ self
Append content to the cell.
-
#column_span(count) ⇒ self
Set column span.
-
#initialize(model = nil) ⇒ TableCellBuilder
constructor
A new instance of TableCellBuilder.
-
#row_span(count) ⇒ self
Set row span.
- #vertical_align(value) ⇒ Object
-
#width(value, rule: nil) ⇒ self
Set cell width.
Methods included from HasShading
Methods included from HasBorders
Methods inherited from BaseBuilder
Constructor Details
#initialize(model = nil) ⇒ TableCellBuilder
Returns a new instance of TableCellBuilder.
20 21 22 23 |
# File 'lib/uniword/builder/table_cell_builder.rb', line 20 def initialize(model = nil) super ensure_cell_structure end |
Class Method Details
.default_model_class ⇒ Object
16 17 18 |
# File 'lib/uniword/builder/table_cell_builder.rb', line 16 def self.default_model_class Wordprocessingml::TableCell end |
Instance Method Details
#<<(element) ⇒ self
Append content to the cell. Routes by type:
- String -> creates a Paragraph with a Run
- Paragraph -> appends to paragraphs
- Table -> appends to nested tables
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/uniword/builder/table_cell_builder.rb', line 32 def <<(element) case element when String para = Wordprocessingml::Paragraph.new para.runs << Wordprocessingml::Run.new(text: element) @model.paragraphs << para track_element_order("p") when Wordprocessingml::Paragraph @model.paragraphs << element track_element_order("p") when Wordprocessingml::Table @model.tables << element track_element_order("tbl") when ParagraphBuilder @model.paragraphs << element.build track_element_order("p") else raise ArgumentError, "Cannot add #{element.class} to table cell" end self end |
#column_span(count) ⇒ self
Set column span
77 78 79 80 81 82 |
# File 'lib/uniword/builder/table_cell_builder.rb', line 77 def column_span(count) ensure_properties @model.properties.grid_span = Wordprocessingml::ValInt.new(value: count) self end |
#row_span(count) ⇒ self
Set row span
88 89 90 91 92 93 |
# File 'lib/uniword/builder/table_cell_builder.rb', line 88 def row_span(count) ensure_properties @model.properties.v_merge = Wordprocessingml::ValInt.new(value: count) self end |
#vertical_align(value) ⇒ Object
67 68 69 70 71 |
# File 'lib/uniword/builder/table_cell_builder.rb', line 67 def vertical_align(value) ensure_properties @model.properties.vertical_align = Properties::CellVerticalAlign.new(value: value.to_s) self end |
#width(value, rule: nil) ⇒ self
Set cell width
59 60 61 62 63 64 65 |
# File 'lib/uniword/builder/table_cell_builder.rb', line 59 def width(value, rule: nil) ensure_properties @model.properties.width ||= Properties::CellWidth.new @model.properties.width.value = value @model.properties.width.rule = rule if rule self end |