Class: Uniword::Builder::ParagraphBuilder

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

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, allocator: nil) ⇒ ParagraphBuilder

Returns a new instance of ParagraphBuilder.



24
25
26
27
28
# File 'lib/uniword/builder/paragraph_builder.rb', line 24

def initialize(model = nil, allocator: nil)
  @allocator = allocator
  super(model)
  assign_tracking_attributes
end

Class Attribute Details

.mutexObject

Returns the value of attribute mutex.



15
16
17
# File 'lib/uniword/builder/paragraph_builder.rb', line 15

def mutex
  @mutex
end

.sequenceObject

Returns the value of attribute sequence.



15
16
17
# File 'lib/uniword/builder/paragraph_builder.rb', line 15

def sequence
  @sequence
end

Instance Attribute Details

#allocatorObject (readonly)

Returns the value of attribute allocator.



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

def allocator
  @allocator
end

Class Method Details

.default_model_classObject



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

def self.default_model_class
  Wordprocessingml::Paragraph
end

Instance Method Details

#<<(element) ⇒ self

Append a child element. Routes by type:

  • String -> creates a Run
  • Run -> appends to runs
  • Hyperlink -> appends to hyperlinks
  • TabStop -> appends to properties.tabs
  • BookmarkStart/End -> appends to bookmarks
  • StructuredDocumentTag -> appends to sdts

Parameters:

Returns:

  • (self)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/uniword/builder/paragraph_builder.rb', line 40

def <<(element)
  case element
  when String
    append_string(element)
  when Omml::Models::CTOMath, Omml::Models::OMath
    @model.o_maths << element
    track_element_order("oMath")
  when Omml::Models::OMathPara
    @model.o_math_paras << element
    track_element_order("oMathPara")
  when Wordprocessingml::Run
    append_run(element)
  when Wordprocessingml::Hyperlink
    @model.hyperlinks << element
    track_element_order("hyperlink")
  when Properties::TabStop
    ensure_properties
    @model.properties.tabs ||= Properties::Tabs.new
    @model.properties.tabs << element
  when Wordprocessingml::BookmarkStart
    @model.bookmark_starts << element
    track_element_order("bookmarkStart")
  when Wordprocessingml::BookmarkEnd
    @model.bookmark_ends << element
    track_element_order("bookmarkEnd")
  when Wordprocessingml::StructuredDocumentTag
    @model.sdts << element
    track_element_order("sdt")
  when Wordprocessingml::SimpleField
    @model.simple_fields << element
    track_element_order("fldSimple")
  when RunBuilder
    append_run(element.build)
  else
    raise ArgumentError, "Cannot add #{element.class} to paragraph"
  end
  self
end

#align=(value) ⇒ Object



88
89
90
91
# File 'lib/uniword/builder/paragraph_builder.rb', line 88

def align=(value)
  ensure_properties.alignment = Properties::Alignment.new(value: value.to_s)
  self
end

#contextual_spacing=(value) ⇒ Object



155
156
157
158
# File 'lib/uniword/builder/paragraph_builder.rb', line 155

def contextual_spacing=(value)
  ensure_properties.contextual_spacing = value
  self
end

#indent(left: nil, right: nil, first_line: nil, hanging: nil) ⇒ self

Set paragraph indentation

Parameters:

  • left (Integer, nil) (defaults to: nil)

    Left indent in twips

  • right (Integer, nil) (defaults to: nil)

    Right indent in twips

  • first_line (Integer, nil) (defaults to: nil)

    First line indent in twips

  • hanging (Integer, nil) (defaults to: nil)

    Hanging indent in twips

Returns:

  • (self)


117
118
119
120
121
122
123
124
125
# File 'lib/uniword/builder/paragraph_builder.rb', line 117

def indent(left: nil, right: nil, first_line: nil, hanging: nil)
  ensure_properties.indentation ||= Properties::Indentation.new
  ind = @model.properties.indentation
  ind.left = left if left
  ind.right = right if right
  ind.first_line = first_line if first_line
  ind.hanging = hanging if hanging
  self
end

#keep_next(value = true) ⇒ Object



143
144
145
146
147
# File 'lib/uniword/builder/paragraph_builder.rb', line 143

def keep_next(value = true)
  ensure_properties.keep_next_wrapper =
    value ? Properties::KeepNext.new(value: true) : nil
  self
end

#numbering(num_id, level = 0) ⇒ self

Set numbering

Parameters:

  • num_id (Integer)

    Numbering definition ID

  • level (Integer) (defaults to: 0)

    Numbering level (0-based, default 0)

Returns:

  • (self)


132
133
134
135
136
137
138
139
140
141
# File 'lib/uniword/builder/paragraph_builder.rb', line 132

def numbering(num_id, level = 0)
  props = ensure_properties
  props.num_id = num_id
  props.ilvl = level
  props.numbering_properties = Properties::NumberingProperties.new(
    num_id: Properties::NumberingId.new(value: num_id),
    ilvl: Properties::NumberingLevel.new(value: level),
  )
  self
end

#outline_level=(value) ⇒ Object



160
161
162
163
# File 'lib/uniword/builder/paragraph_builder.rb', line 160

def outline_level=(value)
  ensure_properties.outline_level = value
  self
end

#page_break_before(value = true) ⇒ Object



149
150
151
152
153
# File 'lib/uniword/builder/paragraph_builder.rb', line 149

def page_break_before(value = true)
  ensure_properties.page_break_before_wrapper =
    value ? Properties::PageBreakBefore.new(value: true) : nil
  self
end

#spacing(before: nil, after: nil, line: nil, rule: nil) ⇒ self

Set paragraph spacing

Parameters:

  • before (Integer, nil) (defaults to: nil)

    Spacing before in twips

  • after (Integer, nil) (defaults to: nil)

    Spacing after in twips

  • line (Integer, nil) (defaults to: nil)

    Line spacing in twips

  • rule (String, nil) (defaults to: nil)

    Line rule ('auto', 'exact', 'atLeast')

Returns:

  • (self)


100
101
102
103
104
105
106
107
108
# File 'lib/uniword/builder/paragraph_builder.rb', line 100

def spacing(before: nil, after: nil, line: nil, rule: nil)
  ensure_properties.spacing ||= Properties::Spacing.new
  props = @model.properties.spacing
  props.before = before if before
  props.after = after if after
  props.line = line if line
  props.line_rule = rule if rule
  self
end

#styleObject



84
85
86
# File 'lib/uniword/builder/paragraph_builder.rb', line 84

def style
  @model.style
end

#style=(name) ⇒ Object



79
80
81
82
# File 'lib/uniword/builder/paragraph_builder.rb', line 79

def style=(name)
  ensure_properties.style = name
  self
end