Class: RubyDocx::Elements::TextRun

Inherits:
Element
  • Object
show all
Defined in:
lib/ruby_docx/elements/text_run.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#doc, #grid, #node, #style

Instance Method Summary collapse

Methods inherited from Element

#elements, #initialize, #inspect, #to_xml

Constructor Details

This class inherits a constructor from RubyDocx::Elements::Element

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



3
4
5
# File 'lib/ruby_docx/elements/text_run.rb', line 3

def color
  @color
end

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/ruby_docx/elements/text_run.rb', line 4

def content
  @content
end

#font_nameObject (readonly)

Returns the value of attribute font_name.



3
4
5
# File 'lib/ruby_docx/elements/text_run.rb', line 3

def font_name
  @font_name
end

#font_sizeObject (readonly)

Returns the value of attribute font_size.



3
4
5
# File 'lib/ruby_docx/elements/text_run.rb', line 3

def font_size
  @font_size
end

Instance Method Details

#to_htmlObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ruby_docx/elements/text_run.rb', line 25

def to_html
  if underline?
    s = "<span>"

    self.elements.map do |ele|
      if ele.class == RubyDocx::Elements::Text
        s += ele.to_s.gsub(/ /, "_")
      else
        s += ele.to_html
      end
    end

    s += "</span>"

    s
  else
    "<span>#{self.elements.map(&:to_html).join}</span>"
  end
end

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_docx/elements/text_run.rb', line 10

def to_s
  if underline?
    self.elements.map do |ele|
      if ele.class == RubyDocx::Elements::Text
        ele.to_s.gsub(/ /, "_")
      else
        ele.to_s
      end
    end.join(" ")

  else
    self.elements.map(&:to_s).join(" ")
  end
end

#underline?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/ruby_docx/elements/text_run.rb', line 6

def underline?
  @node.xpath(".//w:u").size > 0
end