Class: Axlsx::NumData

Inherits:
Object
  • Object
show all
Includes:
OptionsParser
Defined in:
lib/axlsx/drawing/num_data.rb

Overview

This class specifies data for a particular data point. It is used for both numCache and numLit object

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(options = {}) ⇒ NumData

creates a new NumVal object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • formatCode (String)
  • :data (Array)

See Also:



13
14
15
16
17
# File 'lib/axlsx/drawing/num_data.rb', line 13

def initialize(options={})
  @format_code = "General"
  @pt = SimpleTypedList.new NumVal
  parse_options options
end

Instance Attribute Details

#format_codeString

A string representing the format code to apply. For more information see see the SpreadsheetML numFmt element's (ยง18.8.30) formatCode attribute.

Returns:

  • (String)


21
22
23
# File 'lib/axlsx/drawing/num_data.rb', line 21

def format_code
  @format_code
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.



25
26
27
28
29
30
31
# File 'lib/axlsx/drawing/num_data.rb', line 25

def data=(values=[])
  @tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
  values.each do |value|
    value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
    @pt << NumVal.new(:v => value)
  end
end

#to_xml_string(str = "") ⇒ Object

serialize the object



40
41
42
43
44
45
46
47
48
# File 'lib/axlsx/drawing/num_data.rb', line 40

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