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()
74 75 76 |
# File 'lib/uniword/wordprocessingml/run.rb', line 74 def initialize(attrs = {}) super end |
Instance Attribute Details
#parent_paragraph ⇒ Object
Non-serialized runtime reference to parent paragraph for style inheritance
36 37 38 |
# File 'lib/uniword/wordprocessingml/run.rb', line 36 def parent_paragraph @parent_paragraph end |
Instance Method Details
#accept(visitor) ⇒ void
This method returns an undefined value.
Accept a visitor (Visitor pattern)
82 83 84 |
# File 'lib/uniword/wordprocessingml/run.rb', line 82 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)
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/uniword/wordprocessingml/run.rb', line 152 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
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/uniword/wordprocessingml/run.rb', line 169 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
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/uniword/wordprocessingml/run.rb', line 126 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
98 99 100 101 102 103 104 105 |
# File 'lib/uniword/wordprocessingml/run.rb', line 98 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
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/uniword/wordprocessingml/run.rb', line 112 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
89 90 91 |
# File 'lib/uniword/wordprocessingml/run.rb', line 89 def text_string Array(text).join end |