Class: Uniword::Wordprocessingml::Paragraph

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/uniword/wordprocessingml/paragraph.rb

Overview

Paragraph - block-level text element

Generated from OOXML schema: wordprocessingml.yml Element: <w:p>

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_documentObject

Non-serialized runtime reference to parent document for style inheritance This allows runs to access styles_configuration for style property resolution



41
42
43
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 41

def parent_document
  @parent_document
end

Instance Method Details

#accept(visitor) ⇒ Object



144
145
146
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 144

def accept(visitor)
  visitor.visit_paragraph(self)
end

#alignmentObject



114
115
116
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 114

def alignment
  properties&.alignment
end

#each_text_runObject



118
119
120
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 118

def each_text_run(&)
  runs.each(&)
end

#empty?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 106

def empty?
  !runs || runs.empty? || runs.all? { |r| run_text(r).empty? }
end

#extract_sdt_text(sdt) ⇒ Object

Extract text from SDT content



100
101
102
103
104
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 100

def extract_sdt_text(sdt)
  return "" unless sdt.content

  sdt.content.runs.map { |r| r.text.to_s }.join
end

#ilvlObject



130
131
132
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 130

def ilvl
  properties&.ilvl
end

#inspectObject



148
149
150
151
152
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 148

def inspect
  text_preview = text.to_s
  text_preview = "#{text_preview[0, 47]}..." if text_preview.length > 50
  "#<#{self.class} runs=#{runs&.size || 0} text=\"#{text_preview}\">"
end

#num_idObject



126
127
128
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 126

def num_id
  properties&.num_id
end

#numbered?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 140

def numbered?
  properties&.num_id ? true : false
end

#numberingObject



134
135
136
137
138
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 134

def numbering
  return nil unless properties&.num_id

  { num_id: properties.num_id, level: properties.ilvl }
end

#remove!Object



122
123
124
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 122

def remove!
  runs.clear
end

#run_text(run_or_sdt) ⇒ Object

Extract text from a run or SDT element



91
92
93
94
95
96
97
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 91

def run_text(run_or_sdt)
  if run_or_sdt.is_a?(StructuredDocumentTag)
    extract_sdt_text(run_or_sdt)
  else
    run_or_sdt.text.to_s
  end
end

#styleObject



110
111
112
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 110

def style
  properties&.style
end

#textString

Get paragraph text

Returns:

  • (String)

    Combined text from all runs



84
85
86
87
88
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 84

def text
  return "" unless runs

  runs.map { |r| run_text(r) }.join
end