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



45
46
47
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 45

def parent_document
  @parent_document
end

Instance Method Details

#accept(visitor) ⇒ Object



147
148
149
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 147

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

#alignmentObject



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

def alignment
  properties&.alignment
end

#each_text_runObject



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

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

#extract_sdt_text(sdt) ⇒ Object

Extract text from SDT content



103
104
105
106
107
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 103

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

  sdt.content.runs.map(&:text_string).join
end

#ilvlObject



133
134
135
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 133

def ilvl
  properties&.ilvl
end

#inspectObject



151
152
153
154
155
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 151

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



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

def num_id
  properties&.num_id
end

#numbered?Boolean

Returns:

  • (Boolean)


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

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

#numberingObject



137
138
139
140
141
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 137

def numbering
  return nil unless properties&.num_id

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

#remove!Object



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

def remove!
  runs.clear
end

#run_text(run_or_sdt) ⇒ Object

Extract text from a run or SDT element



94
95
96
97
98
99
100
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 94

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

#styleObject



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

def style
  Array(properties&.style).first
end

#textString

Get paragraph text

Returns:

  • (String)

    Combined text from all runs



87
88
89
90
91
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 87

def text
  return "" unless runs

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