Class: Uniword::Builder::HeaderFooterBuilder
- Inherits:
-
Object
- Object
- Uniword::Builder::HeaderFooterBuilder
- Defined in:
- lib/uniword/builder/header_footer_builder.rb
Overview
Builds and configures Header or Footer objects.
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#<<(element) ⇒ self
Append content to the header/footer.
-
#build ⇒ Object
Return the underlying Header or Footer model.
-
#initialize(kind, type: "default") ⇒ HeaderFooterBuilder
constructor
A new instance of HeaderFooterBuilder.
-
#paragraph(text = nil) {|ParagraphBuilder| ... } ⇒ ParagraphBuilder
Add a paragraph with configuration.
Constructor Details
#initialize(kind, type: "default") ⇒ HeaderFooterBuilder
Returns a new instance of HeaderFooterBuilder.
20 21 22 23 24 25 26 27 |
# File 'lib/uniword/builder/header_footer_builder.rb', line 20 def initialize(kind, type: "default") @kind = kind @model = if kind == :header Wordprocessingml::Header.new else Wordprocessingml::Footer.new end end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
18 19 20 |
# File 'lib/uniword/builder/header_footer_builder.rb', line 18 def kind @kind end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
18 19 20 |
# File 'lib/uniword/builder/header_footer_builder.rb', line 18 def model @model end |
Instance Method Details
#<<(element) ⇒ self
Append content to the header/footer
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/uniword/builder/header_footer_builder.rb', line 33 def <<(element) case element when String para = Wordprocessingml::Paragraph.new para.runs << Wordprocessingml::Run.new(text: element) @model.paragraphs << para when Wordprocessingml::Run # Auto-wrap Run in a paragraph, appending to the last one if possible if @model.paragraphs.empty? para = Wordprocessingml::Paragraph.new para.runs << element @model.paragraphs << para else @model.paragraphs.last.runs << element end when Wordprocessingml::Paragraph @model.paragraphs << element when Wordprocessingml::Table @model.tables << element when ParagraphBuilder @model.paragraphs << element.build else raise ArgumentError, "Cannot add #{element.class} to #{@kind}" end self end |
#build ⇒ Object
Return the underlying Header or Footer model
74 75 76 |
# File 'lib/uniword/builder/header_footer_builder.rb', line 74 def build @model end |
#paragraph(text = nil) {|ParagraphBuilder| ... } ⇒ ParagraphBuilder
Add a paragraph with configuration
65 66 67 68 69 70 71 |
# File 'lib/uniword/builder/header_footer_builder.rb', line 65 def paragraph(text = nil, &block) para = ParagraphBuilder.new para << text if text yield(para) if block @model.paragraphs << para.build para end |