class Axlsx::Title

A Title stores information about the title of a chart

Attributes

cell[R]

The cell that holds the text for the title. Setting this property will automatically update the text attribute. @return [Cell]

text[R]

The text to be shown. Setting this property directly with a string will remove the cell reference. @return [String]

text_size[R]

Text size property @return [String]

Public Class Methods

new(title="", title_size="") click to toggle source

Creates a new Title object @param [String, Cell] title The cell or string to be used for the chart's title

# File lib/axlsx/drawing/title.rb, line 20
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

Public Instance Methods

cell=(v) click to toggle source

@see cell

# File lib/axlsx/drawing/title.rb, line 47
def cell=(v)
  DataTypeValidator.validate 'Title.text', Cell, v
  @cell = v
  @text = v.value.to_s
  v
end
text=(v) click to toggle source

@see text

# File lib/axlsx/drawing/title.rb, line 31
def text=(v)
  DataTypeValidator.validate 'Title.text', String, v
  @text = v
  @cell = nil
  v
end
text_size=(v) click to toggle source

@see text_size

# File lib/axlsx/drawing/title.rb, line 39
def text_size=(v)
  DataTypeValidator.validate 'Title.text_size', String, v
  @text_size = v
  @cell = nil
  v
end
to_xml_string(str = '') click to toggle source

Serializes the object @param [String] str @return [String]

# File lib/axlsx/drawing/title.rb, line 62
def to_xml_string(str = '')
  str << '<c:title>'
  unless @text.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