Class: RubyDocx::Elements::TextRun
- Defined in:
- lib/ruby_docx/elements/text_run.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#content ⇒ Object
Returns the value of attribute content.
-
#font_name ⇒ Object
readonly
Returns the value of attribute font_name.
-
#font_size ⇒ Object
readonly
Returns the value of attribute font_size.
Attributes inherited from Element
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
#color ⇒ Object (readonly)
Returns the value of attribute color.
3 4 5 |
# File 'lib/ruby_docx/elements/text_run.rb', line 3 def color @color end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/ruby_docx/elements/text_run.rb', line 4 def content @content end |
#font_name ⇒ Object (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_size ⇒ Object (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_html ⇒ Object
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_s ⇒ Object
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
6 7 8 |
# File 'lib/ruby_docx/elements/text_run.rb', line 6 def underline? @node.xpath(".//w:u").size > 0 end |