summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/title.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
committerRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
commite53f04284618713b0a90b7a691425c380e829476 (patch)
tree801fea138160f9af426d62bf94ad5bf97123ece9 /lib/axlsx/drawing/title.rb
downloadcaxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz
caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip
first commit
Diffstat (limited to 'lib/axlsx/drawing/title.rb')
-rw-r--r--lib/axlsx/drawing/title.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb
new file mode 100644
index 00000000..496f5f7b
--- /dev/null
+++ b/lib/axlsx/drawing/title.rb
@@ -0,0 +1,69 @@
+module Axlsx
+ # A Title stores information about the title of a chart
+ class Title
+
+ # The text to be shown. Setting this property directly with a string will remove the cell reference.
+ # @return [String]
+ attr_accessor :text
+
+ # The cell that holds the text for the title. Setting this property will automatically update the text attribute.
+ # @return [Cell]
+ attr_accessor :cell
+
+ # Creates a new Title object
+ # @param [String, Cell] title The cell or string to be used for the chart's title
+ def initialize(title="")
+ self.cell = title if title.is_a?(Cell)
+ self.text = title.to_s unless title.is_a?(Cell)
+ end
+
+ def text=(v)
+ DataTypeValidator.validate 'Title.text', String, v
+ @text = v
+ @cell = nil
+ v
+ end
+
+ def cell=(v)
+ DataTypeValidator.validate 'Title.text', Cell, v
+ @cell = v
+ @text = v.value.to_s
+ v
+ end
+
+ # Not implemented at this time.
+ #def tx=(v) DataTypeValidator.validate 'Title.tx', Tx, v; @tx=v; end
+ #def layout=(v) DataTypeValidator.validate 'Title.layout', Layout, v; @layout = v; end
+ #def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end
+ #def spPr=(v) DataTypeValidator.validate 'Title.spPr', SpPr, v; @spPr = v; end
+
+ # Serializes the chart title
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
+ # @return [String]
+ def to_xml(xml)
+ xml.send('c:title') {
+ xml.send('c:tx') {
+ xml.send('c:strRef') {
+ xml.send('c:f', range)
+ xml.send('c:strCache') {
+ xml.send('c:ptCount', :val=>1)
+ xml.send('c:pt', :idx=>0) {
+ xml.send('c:v', @text)
+ }
+ }
+ }
+ }
+ }
+ end
+
+ private
+
+ # returns the excel style abslute reference for the title when title is a Cell object
+ # @return [String]
+ def range
+ return "" unless @data.is_a?(Cell)
+ "#{@data.row.worksheet.name}!#{data.row.r_abs}"
+ end
+
+ end
+end