Class: Axlsx::StrData

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

Overview

This specifies the last string data used for a chart. (e.g. strLit and strCache) This class is extended for NumData to include the formatCode attribute required for numLit and numCache

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ StrData

creates a new StrVal object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :data (Array)
  • :tag_name (String)


11
12
13
14
15
16
17
18
# File 'lib/axlsx/drawing/str_data.rb', line 11

def initialize(options={})
  @tag_prefix = :str
  @type = StrVal
  @pt = SimpleTypedList.new(@type)
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Method Details

#data=(values = []) ⇒ Object

Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.

Parameters:

  • values (Array) (defaults to: [])

    An array of cells or values.



22
23
24
25
26
27
28
# File 'lib/axlsx/drawing/str_data.rb', line 22

def data=(values=[])
  @tag_name = values.first.is_a?(Cell) ? :strCache : :strLit
  values.each do |value|
    v = value.is_a?(Cell) ? value.value : value
    @pt << @type.new(:v => v)
  end
end

#to_xml_string(str = "") ⇒ Object

serialize the object



31
32
33
34
35
36
37
38
# File 'lib/axlsx/drawing/str_data.rb', line 31

def to_xml_string(str = "")
  str << '<c:' << @tag_name.to_s << '>'
  str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
  @pt.each_with_index do |value, index|
    value.to_xml_string index, str
  end
  str << '</c:' << @tag_name.to_s << '>'
end