Class: Rbpptx::Run
- Inherits:
-
Object
- Object
- Rbpptx::Run
- Defined in:
- lib/rbpptx/run.rb
Overview
A single run (+<a:r>+) inside a paragraph.
Runs are the smallest unit of text that shares a single set of run properties (+<a:rPr>+: font, size, color, language, hyperlink, …). The text setter replaces only the content of the run’s <a:t> element, so every other property of the run survives the edit untouched — the surgical counterpart to the bulldozer-style Shape#text= setter.
Constant Summary collapse
- A_NS =
"http://schemas.openxmlformats.org/drawingml/2006/main".freeze
Instance Method Summary collapse
-
#initialize(node:, slide: nil) ⇒ Run
constructor
A new instance of Run.
-
#text ⇒ String
The run’s text content (the inner text of <a:t>), or “” if the run has no <a:t> element.
-
#text=(new_text) ⇒ String
Replaces the run’s text content.
Constructor Details
#initialize(node:, slide: nil) ⇒ Run
Returns a new instance of Run.
17 18 19 20 |
# File 'lib/rbpptx/run.rb', line 17 def initialize(node:, slide: nil) @node = node @slide = end |
Instance Method Details
#text ⇒ String
Returns the run’s text content (the inner text of <a:t>), or “” if the run has no <a:t> element.
24 25 26 27 |
# File 'lib/rbpptx/run.rb', line 24 def text t = @node.at_xpath("./a:t", "a" => A_NS) t ? t.text : "" end |
#text=(new_text) ⇒ String
Replaces the run’s text content. Only the <a:t> element’s character data is rewritten; <a:rPr> and any other children of the run are left in place. If the run has no <a:t> element, one is appended.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rbpptx/run.rb', line 35 def text=(new_text) value = new_text.to_s t = @node.at_xpath("./a:t", "a" => A_NS) if t t.content = value else @node.add_child("<a:t>#{CGI.escapeHTML(value)}</a:t>") end @slide&.mark_dirty! value end |