Class: Docx::Elements::Containers::TextRun
- Inherits:
-
Object
- Object
- Docx::Elements::Containers::TextRun
- Defined in:
- lib/docx/containers/text_run.rb
Constant Summary collapse
- DEFAULT_FORMATTING =
{ italic: false, bold: false, underline: false }
- TAG =
'r'
Constants included from Element
Instance Attribute Summary collapse
-
#formatting ⇒ Object
readonly
Returns the value of attribute formatting.
-
#text ⇒ Object
Returns the value of attribute text.
Attributes included from Element
Instance Method Summary collapse
- #bolded? ⇒ Boolean
-
#initialize(node) ⇒ TextRun
constructor
A new instance of TextRun.
- #italicized? ⇒ Boolean
- #parse_formatting ⇒ Object
-
#parse_text ⇒ Object
Returns text contained within text run.
- #to_s ⇒ Object
- #underlined? ⇒ Boolean
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) ⇒ TextRun
Returns a new instance of TextRun.
21 22 23 24 25 26 27 |
# File 'lib/docx/containers/text_run.rb', line 21 def initialize(node) @node = node @text_nodes = @node.xpath('w:t').map {|t_node| Elements::Text.new(t_node) } @properties_tag = 'rPr' @text = parse_text || '' @formatting = parse_formatting || DEFAULT_FORMATTING end |
Instance Attribute Details
#formatting ⇒ Object (readonly)
Returns the value of attribute formatting.
19 20 21 |
# File 'lib/docx/containers/text_run.rb', line 19 def formatting @formatting end |
#text ⇒ Object
Returns the value of attribute text.
18 19 20 |
# File 'lib/docx/containers/text_run.rb', line 18 def text @text end |
Instance Method Details
#bolded? ⇒ Boolean
60 61 62 |
# File 'lib/docx/containers/text_run.rb', line 60 def bolded? @formatting[:bold] end |
#italicized? ⇒ Boolean
56 57 58 |
# File 'lib/docx/containers/text_run.rb', line 56 def italicized? @formatting[:italic] end |
#parse_formatting ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/docx/containers/text_run.rb', line 44 def parse_formatting { italic: !@node.xpath('.//w:i').empty?, bold: !@node.xpath('.//w:b').empty?, underline: !@node.xpath('.//w:u').empty? } end |
#parse_text ⇒ Object
Returns text contained within text run
40 41 42 |
# File 'lib/docx/containers/text_run.rb', line 40 def parse_text @text_nodes.map(&:content).join('') end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/docx/containers/text_run.rb', line 52 def to_s @text end |
#underlined? ⇒ Boolean
64 65 66 |
# File 'lib/docx/containers/text_run.rb', line 64 def underlined? @formatting[:underline] end |