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
-
#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
Handle direct text insertion into paragraph on some conditions.
- #text_runs ⇒ Object
- #to_s ⇒ Object (also: #text)
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
42 43 44 |
# File 'lib/docx/containers/paragraph.rb', line 42 def each_text_run text_runs.each { |tr| yield(tr) } end |
#text=(content) ⇒ Object
Handle direct text insertion into paragraph on some conditions
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
38 39 40 |
# File 'lib/docx/containers/paragraph.rb', line 38 def text_runs @node.xpath('w:r').map {|r_node| Containers::TextRun.new(r_node) } end |
#to_s ⇒ Object Also known as: text
34 35 36 |
# File 'lib/docx/containers/paragraph.rb', line 34 def to_s text_runs.map(&:text).join('') end |