Class: Uniword::Wordprocessingml::Paragraph
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Wordprocessingml::Paragraph
- 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
-
#parent_document ⇒ Object
Non-serialized runtime reference to parent document for style inheritance This allows runs to access styles_configuration for style property resolution.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #alignment ⇒ Object
- #each_text_run ⇒ Object
- #empty? ⇒ Boolean
-
#extract_sdt_text(sdt) ⇒ Object
Extract text from SDT content.
- #ilvl ⇒ Object
- #inspect ⇒ Object
- #num_id ⇒ Object
- #numbered? ⇒ Boolean
- #numbering ⇒ Object
- #remove! ⇒ Object
-
#run_text(run_or_sdt) ⇒ Object
Extract text from a run or SDT element.
- #style ⇒ Object
-
#text ⇒ String
Get paragraph text.
Instance Attribute Details
#parent_document ⇒ Object
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 |
#alignment ⇒ Object
114 115 116 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 114 def alignment properties&.alignment end |
#each_text_run ⇒ Object
118 119 120 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 118 def each_text_run(&) runs.each(&) end |
#empty? ⇒ 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 |
#ilvl ⇒ Object
130 131 132 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 130 def ilvl properties&.ilvl end |
#inspect ⇒ Object
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_id ⇒ Object
126 127 128 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 126 def num_id properties&.num_id end |
#numbered? ⇒ Boolean
140 141 142 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 140 def numbered? properties&.num_id ? true : false end |
#numbering ⇒ Object
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 |
#style ⇒ Object
110 111 112 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 110 def style properties&.style end |
#text ⇒ String
Get paragraph text
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 |