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.
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()
69 70 71 |
# File 'lib/uniword/wordprocessingml/run.rb', line 69 def initialize(attrs = {}) super end |
Instance Attribute Details
#parent_paragraph ⇒ Object
Non-serialized runtime reference to parent paragraph for style inheritance
34 35 36 |
# File 'lib/uniword/wordprocessingml/run.rb', line 34 def parent_paragraph @parent_paragraph end |
Instance Method Details
#accept(visitor) ⇒ void
This method returns an undefined value.
Accept a visitor (Visitor pattern)
77 78 79 |
# File 'lib/uniword/wordprocessingml/run.rb', line 77 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)
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/uniword/wordprocessingml/run.rb', line 136 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
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/uniword/wordprocessingml/run.rb', line 153 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
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/uniword/wordprocessingml/run.rb', line 110 def inspect text_preview = text.to_s 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
86 87 88 89 90 91 |
# File 'lib/uniword/wordprocessingml/run.rb', line 86 def substitute(pattern, replacement) return self unless text self.text = text.to_s.gsub(pattern, replacement) self end |
#substitute_with_block(pattern) {|MatchData| ... } ⇒ self
Substitute with block
98 99 100 101 102 103 104 105 |
# File 'lib/uniword/wordprocessingml/run.rb', line 98 def substitute_with_block(pattern, &block) return self unless text self.text = text.to_s.gsub(pattern) do |_match_str| yield(Regexp.last_match) end self end |