Class: Axlsx::Title
- Inherits:
-
Object
- Object
- Axlsx::Title
- Defined in:
- lib/axlsx/drawing/title.rb
Overview
A Title stores information about the title of a chart
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cell ⇒ Cell
The cell that holds the text for the title.
-
#text ⇒ String
The text to be shown.
-
#text_size ⇒ String
Text size property.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Check if the title is empty.
-
#initialize(title = "", title_size = "") ⇒ Title
constructor
Creates a new Title object.
-
#to_xml_string(str = '') ⇒ String
Serializes the object.
Constructor Details
#initialize(title = "", title_size = "") ⇒ Title
Creates a new Title object
18 19 20 21 22 23 24 25 26 |
# File 'lib/axlsx/drawing/title.rb', line 18 def initialize(title = "", title_size = "") self.cell = title if title.is_a?(Cell) self.text = title.to_s unless title.is_a?(Cell) if title_size.to_s.empty? self.text_size = "1600" else self.text_size = title_size.to_s end end |
Instance Attribute Details
#cell ⇒ Cell
The cell that holds the text for the title. Setting this property will automatically update the text attribute.
14 15 16 |
# File 'lib/axlsx/drawing/title.rb', line 14 def cell @cell end |
#text ⇒ String
The text to be shown. Setting this property directly with a string will remove the cell reference.
6 7 8 |
# File 'lib/axlsx/drawing/title.rb', line 6 def text @text end |
#text_size ⇒ String
Text size property
10 11 12 |
# File 'lib/axlsx/drawing/title.rb', line 10 def text_size @text_size end |
Instance Method Details
#empty? ⇒ Boolean
Check if the title is empty.
A title is considered empty if it is an empty string. If the title references a cell it is not empty, even if the referenced cell is blank (because the cell’s value could still change later).
58 59 60 |
# File 'lib/axlsx/drawing/title.rb', line 58 def empty? @text.empty? && @cell.nil? end |
#to_xml_string(str = '') ⇒ String
Serializes the object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/axlsx/drawing/title.rb', line 70 def to_xml_string(str = '') str << '<c:title>' unless empty? clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s)) str << '<c:tx>' if @cell.is_a?(Cell) str << '<c:strRef>' str << ('<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>') str << '<c:strCache>' str << '<c:ptCount val="1"/>' str << '<c:pt idx="0">' str << ('<c:v>' << clean_value << '</c:v>') str << '</c:pt>' str << '</c:strCache>' str << '</c:strRef>' else str << '<c:rich>' str << '<a:bodyPr/>' str << '<a:lstStyle/>' str << '<a:p>' str << '<a:r>' str << ('<a:rPr sz="' << @text_size.to_s << '"/>') str << ('<a:t>' << clean_value << '</a:t>') str << '</a:r>' str << '</a:p>' str << '</c:rich>' end str << '</c:tx>' end str << '<c:layout/>' str << '<c:overlay val="0"/>' str << '</c:title>' end |