Class: Uniword::Wordprocessingml::Run

Inherits:
Lutaml::Model::Serializable
  • Object
show all
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

Instance Method Summary collapse

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_paragraphObject

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)

Parameters:

  • visitor (BaseVisitor)

    The visitor to accept



77
78
79
# File 'lib/uniword/wordprocessingml/run.rb', line 77

def accept(visitor)
  visitor.visit_run(self)
end

#effective_run_propertiesRunProperties?

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):

  1. Explicit run property (highest)

  2. Paragraph style’s run property (from rPr in style definition)

  3. Style’s basedOn chain (cascade up to Normal/Default)

Returns:



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_sizeInteger?

Convenience accessor for font size in points (half-points in OOXML) Returns effective size from inherited style if not explicitly set

Returns:

  • (Integer, nil)

    Font size in points, or nil



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

#inspectString

Custom inspect for readable output

Returns:

  • (String)

    Human-readable representation



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

Parameters:

  • pattern (Regexp, String)

    Pattern to match

  • replacement (String)

    Replacement text

Returns:

  • (self)

    For method chaining



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

Parameters:

  • pattern (Regexp, String)

    Pattern to match

Yields:

  • (MatchData)

    Block receives match data object

Returns:

  • (self)

    For method chaining



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