Class: Uniword::Builder::SectionBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- Uniword::Builder::SectionBuilder
- Defined in:
- lib/uniword/builder/section_builder.rb
Overview
Builds and configures SectionProperties objects.
Instance Attribute Summary
Attributes inherited from BaseBuilder
Class Method Summary collapse
Instance Method Summary collapse
- #columns(count: 1, spacing: 720) ⇒ Object
- #footer(type: "default", &block) ⇒ Object
-
#footer_models ⇒ Object
Built footer content models keyed by type.
- #header(type: "default", &block) ⇒ Object
-
#header_models ⇒ Object
Built header content models keyed by type.
-
#initialize(model = nil) ⇒ SectionBuilder
constructor
A new instance of SectionBuilder.
- #margins(top: 1440, bottom: 1440, left: 1440, right: 1440, header: 720, footer: 720, gutter: 0) ⇒ Object
- #page_numbering(start: nil, format: nil) ⇒ Object
- #page_size(width: Wordprocessingml::PageDefaults::LETTER_WIDTH, height: Wordprocessingml::PageDefaults::LETTER_HEIGHT, orientation: "portrait") ⇒ Object
- #type=(value) ⇒ Object
Methods inherited from BaseBuilder
Constructor Details
#initialize(model = nil) ⇒ SectionBuilder
Returns a new instance of SectionBuilder.
24 25 26 27 |
# File 'lib/uniword/builder/section_builder.rb', line 24 def initialize(model = nil) super ensure_section_defaults end |
Class Method Details
.default_model_class ⇒ Object
20 21 22 |
# File 'lib/uniword/builder/section_builder.rb', line 20 def self.default_model_class Wordprocessingml::SectionProperties end |
Instance Method Details
#columns(count: 1, spacing: 720) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/uniword/builder/section_builder.rb', line 64 def columns(count: 1, spacing: 720) @model.columns ||= Wordprocessingml::Columns.new @model.columns.num = count @model.columns.space = spacing self end |
#footer(type: "default", &block) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/uniword/builder/section_builder.rb', line 83 def (type: "default", &block) hf = HeaderFooterBuilder.new(:footer, type: type) block&.call(hf) ref = Wordprocessingml::FooterReference.new( type: type, r_id: "rIdFtr#{type}", ) @model. << ref @footer_builders ||= {} @footer_builders[type] = hf hf end |
#footer_models ⇒ Object
Built footer content models keyed by type.
101 102 103 |
# File 'lib/uniword/builder/section_builder.rb', line 101 def (@footer_builders || {}).transform_values(&:build) end |
#header(type: "default", &block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/uniword/builder/section_builder.rb', line 71 def header(type: "default", &block) hf = HeaderFooterBuilder.new(:header, type: type) block&.call(hf) ref = Wordprocessingml::HeaderReference.new( type: type, r_id: "rIdHdr#{type}", ) @model.header_references << ref @header_builders ||= {} @header_builders[type] = hf hf end |
#header_models ⇒ Object
Built header content models keyed by type.
96 97 98 |
# File 'lib/uniword/builder/section_builder.rb', line 96 def header_models (@header_builders || {}).transform_values(&:build) end |
#margins(top: 1440, bottom: 1440, left: 1440, right: 1440, header: 720, footer: 720, gutter: 0) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/uniword/builder/section_builder.rb', line 44 def margins(top: 1440, bottom: 1440, left: 1440, right: 1440, header: 720, footer: 720, gutter: 0) @model.page_margins ||= Wordprocessingml::PageMargins.new @model.page_margins.top = top @model.page_margins.bottom = bottom @model.page_margins.left = left @model.page_margins.right = right @model.page_margins.header = header @model.page_margins. = @model.page_margins.gutter = gutter self end |
#page_numbering(start: nil, format: nil) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/uniword/builder/section_builder.rb', line 57 def page_numbering(start: nil, format: nil) @model.page_numbering ||= Wordprocessingml::PageNumbering.new @model.page_numbering.start = start if start @model.page_numbering.format = format if format self end |
#page_size(width: Wordprocessingml::PageDefaults::LETTER_WIDTH, height: Wordprocessingml::PageDefaults::LETTER_HEIGHT, orientation: "portrait") ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/uniword/builder/section_builder.rb', line 34 def page_size(width: Wordprocessingml::PageDefaults::LETTER_WIDTH, height: Wordprocessingml::PageDefaults::LETTER_HEIGHT, orientation: "portrait") @model.page_size ||= Wordprocessingml::PageSize.new @model.page_size.width = width @model.page_size.height = height @model.page_size.orientation = orientation self end |
#type=(value) ⇒ Object
29 30 31 32 |
# File 'lib/uniword/builder/section_builder.rb', line 29 def type=(value) @model.type = value self end |