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
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 |
#alignment ⇒ Object
117 118 119 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 117 def alignment properties&.alignment end |
#each_text_run ⇒ Object
121 122 123 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 121 def each_text_run(&) runs.each(&) end |
#empty? ⇒ 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 |
#ilvl ⇒ Object
133 134 135 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 133 def ilvl properties&.ilvl end |
#inspect ⇒ Object
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_id ⇒ Object
129 130 131 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 129 def num_id properties&.num_id end |
#numbered? ⇒ Boolean
143 144 145 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 143 def numbered? properties&.num_id ? true : false end |
#numbering ⇒ Object
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 |
#style ⇒ Object
113 114 115 |
# File 'lib/uniword/wordprocessingml/paragraph.rb', line 113 def style Array(properties&.style).first end |
#text ⇒ String
Get paragraph text
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 |