Class: Axlsx::Title

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/drawing/title.rb

Overview

A Title stores information about the title of a chart

Direct Known Subclasses

SeriesTitle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = "") ⇒ Title

Creates a new Title object

Parameters:

  • title (String, Cell) (defaults to: "")

    The cell or string to be used for the chart’s title



16
17
18
19
# File 'lib/axlsx/drawing/title.rb', line 16

def initialize(title="")
  self.cell = title if title.is_a?(Cell)
  self.text = title.to_s unless title.is_a?(Cell)
end

Instance Attribute Details

#cellCell

The cell that holds the text for the title. Setting this property will automatically update the text attribute.

Returns:



12
13
14
# File 'lib/axlsx/drawing/title.rb', line 12

def cell
  @cell
end

#textString

The text to be shown. Setting this property directly with a string will remove the cell reference.

Returns:

  • (String)


8
9
10
# File 'lib/axlsx/drawing/title.rb', line 8

def text
  @text
end

Instance Method Details

#to_xml(xml) ⇒ String

Serializes the chart title

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/axlsx/drawing/title.rb', line 45

def to_xml(xml)
  xml[:c].title {
    unless @text.empty?
      xml[:c].tx {
        xml[:c].strRef {
          xml[:c].f Axlsx::cell_range([@cell])
          xml[:c].strCache {
            xml[:c].ptCount :val=>1
            xml[:c].pt(:idx=>0) {
              xml[:c].v @text
            }
          }
        }
      }
    end
    xml[:c].layout
    xml[:c].overlay :val=>0
  }      
end