Class: Uniword::Wordprocessingml::Run
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Wordprocessingml::Run
- Defined in:
- lib/uniword/wordprocessingml/run.rb
Overview
Text run - inline text with formatting
Generated from OOXML schema: wordprocessingml.yml Element: <w:r>
Instance Attribute Summary collapse
-
#parent_paragraph ⇒ Object
Non-serialized runtime reference to parent paragraph for style inheritance.
Instance Method Summary collapse
-
#accept(visitor) ⇒ void
Accept a visitor (Visitor pattern).
-
#effective_run_properties ⇒ RunProperties?
Get effective run properties including inherited from paragraph style.
-
#font_size ⇒ Integer?
Convenience accessor for font size in points (half-points in OOXML) Returns effective size from inherited style if not explicitly set.
-
#initialize(attrs = {}) ⇒ Run
constructor
Initialize with text normalization With Text.cast defined, lutaml-model handles String->Text conversion during attribute assignment via attr.cast_value().
-
#inspect ⇒ String
Custom inspect for readable output.
-
#substitute(pattern, replacement) ⇒ self
Substitute text in run.
-
#substitute_with_block(pattern) {|MatchData| ... } ⇒ self
Substitute with block.
-
#text_string ⇒ String
Combined string content of all text elements in the run.
Constructor Details
#initialize(attrs = {}) ⇒ Run
Initialize with text normalization With Text.cast defined, lutaml-model handles String->Text conversion during attribute assignment via attr.cast_value()
77 78 79 |
# File 'lib/uniword/wordprocessingml/run.rb', line 77 def initialize(attrs = {}) super end |
Instance Attribute Details
#parent_paragraph ⇒ Object
Non-serialized runtime reference to parent paragraph for style inheritance
37 38 39 |
# File 'lib/uniword/wordprocessingml/run.rb', line 37 def parent_paragraph @parent_paragraph end |
Instance Method Details
#accept(visitor) ⇒ void
This method returns an undefined value.
Accept a visitor (Visitor pattern)
85 86 87 |
# File 'lib/uniword/wordprocessingml/run.rb', line 85 def accept(visitor) visitor.visit_run(self) end |
#effective_run_properties ⇒ RunProperties?
Get effective run properties including inherited from paragraph style
This implements OOXML style inheritance where run properties are resolved per-property with explicit values taking precedence over inherited style values.
Priority order (per property):
- Explicit run property (highest)
- Paragraph style's run property (from rPr in style definition)
- Style's basedOn chain (cascade up to Normal/Default)
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/uniword/wordprocessingml/run.rb', line 155 def effective_run_properties inherited = inherited_from_style # If no explicit properties, return inherited directly return inherited unless properties # If no inherited properties, return explicit directly return properties unless inherited # Merge: explicit overrides inherited per-property merge_properties(inherited, properties) end |
#font_size ⇒ Integer?
Convenience accessor for font size in points (half-points in OOXML) Returns effective size from inherited style if not explicitly set
172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/uniword/wordprocessingml/run.rb', line 172 def font_size effective = effective_run_properties return nil unless effective size_val = effective.size return nil unless size_val # size is stored in half-points, convert to points raw = size_val.value return nil unless raw half_pts = raw.to_i half_pts.positive? ? half_pts / 2 : nil end |
#inspect ⇒ String
Custom inspect for readable output
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/uniword/wordprocessingml/run.rb', line 129 def inspect text_preview = text_string text_preview = "#{text_preview[0, 37]}..." if text_preview.length > 40 flags = [] flags << "bold" if properties&.bold&.value == true flags << "italic" if properties&.italic&.value == true if flags.any? "#<#{self.class} text=\"#{text_preview}\", #{flags.join(', ')}>" else "#<#{self.class} text=\"#{text_preview}\">" end end |
#substitute(pattern, replacement) ⇒ self
Substitute text in run
101 102 103 104 105 106 107 108 |
# File 'lib/uniword/wordprocessingml/run.rb', line 101 def substitute(pattern, replacement) Array(text).each do |t| content = t.content.to_s.gsub(pattern, replacement) t.content = content t.xml_space = Text.preserve_whitespace?(content) ? "preserve" : nil end self end |
#substitute_with_block(pattern) {|MatchData| ... } ⇒ self
Substitute with block
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/uniword/wordprocessingml/run.rb', line 115 def substitute_with_block(pattern, &block) Array(text).each do |t| content = t.content.to_s.gsub(pattern) do |_match_str| yield(Regexp.last_match) end t.content = content t.xml_space = Text.preserve_whitespace?(content) ? "preserve" : nil end self end |
#text_string ⇒ String
Combined string content of all text elements in the run
92 93 94 |
# File 'lib/uniword/wordprocessingml/run.rb', line 92 def text_string Array(text).join end |