Class: Docx::Elements::Containers::Paragraph
- Inherits:
-
Object
- Object
- Docx::Elements::Containers::Paragraph
- Defined in:
- lib/docx/containers/paragraph.rb
Constant Summary collapse
- TAG =
'p'
Constants included from Element
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
-
#each_text_run ⇒ Object
Iterate over each text run within a paragraph.
-
#initialize(node) ⇒ Paragraph
constructor
Child elements: pPr, r, fldSimple, hlink, subDoc msdn.microsoft.com/en-us/library/office/ee364458(v=office.11).aspx.
-
#text=(content) ⇒ Object
Set text of paragraph.
-
#text_runs ⇒ Object
Array of text runs contained within paragraph.
-
#to_s ⇒ Object
(also: #text)
Return text of paragraph.
Methods included from Element
#append_to, #copy, included, #insert_after, #insert_before, #parent, #parent_paragraph, #prepend_to
Methods included from Container
Constructor Details
#initialize(node) ⇒ Paragraph
Child elements: pPr, r, fldSimple, hlink, subDoc msdn.microsoft.com/en-us/library/office/ee364458(v=office.11).aspx
15 16 17 18 |
# File 'lib/docx/containers/paragraph.rb', line 15 def initialize(node) @node = node @properties_tag = 'pPr' end |
Instance Method Details
#each_text_run ⇒ Object
Iterate over each text run within a paragraph
45 46 47 |
# File 'lib/docx/containers/paragraph.rb', line 45 def each_text_run text_runs.each { |tr| yield(tr) } end |
#text=(content) ⇒ Object
Set text of paragraph
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/docx/containers/paragraph.rb', line 21 def text=(content) if text_runs.size == 1 text_runs.first.text = content elsif text_runs.size == 0 new_r = TextRun.create_within(self) new_r.text = content else text_runs.each {|r| r.node.remove } new_r = TextRun.create_within(self) new_r.text = content end end |
#text_runs ⇒ Object
Array of text runs contained within paragraph
40 41 42 |
# File 'lib/docx/containers/paragraph.rb', line 40 def text_runs @node.xpath('w:r').map {|r_node| Containers::TextRun.new(r_node) } end |
#to_s ⇒ Object Also known as: text
Return text of paragraph
35 36 37 |
# File 'lib/docx/containers/paragraph.rb', line 35 def to_s text_runs.map(&:text).join('') end |