Class: Axlsx::NumDataSource

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

Overview

A numeric data source for use by charts.

Direct Known Subclasses

AxDataSource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NumDataSource

creates a new NumDataSource object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • data (Array)

    An array of Cells or Numeric objects

  • tag_name (Symbol)

    see tag_name



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/axlsx/drawing/num_data_source.rb', line 22

def initialize(options={})
  # override these three in child classes
  @data_type ||= NumData
  @tag_name ||= :val
  @ref_tag_name ||= :numRef

  @f = nil
  @data = @data_type.new(options)
  if options[:data] && options[:data].first.is_a?(Cell)
    @f = Axlsx::cell_range(options[:data])
  end
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/axlsx/drawing/num_data_source.rb', line 11

def data
  @data
end

#tag_nameSymbol

The tag name to use when serializing this data source. Only items defined in allowed_tag_names are allowed

Returns:

  • (Symbol)


9
10
11
# File 'lib/axlsx/drawing/num_data_source.rb', line 9

def tag_name
  @tag_name
end

Class Method Details

.allowed_tag_namesArray

allowed element tag names

Returns:

  • (Array)


15
16
17
# File 'lib/axlsx/drawing/num_data_source.rb', line 15

def self.allowed_tag_names
  [:yVal, :val]
end

Instance Method Details

#to_xml_string(str = "") ⇒ Object

serialize the object

Parameters:

  • str (String) (defaults to: "")


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/axlsx/drawing/num_data_source.rb', line 47

def to_xml_string(str="")
  str << '<c:' << tag_name.to_s << '>'
  if @f
    str << '<c:' << @ref_tag_name.to_s << '>'
    str << '<c:f>' << @f.to_s << '</c:f>'
  end
  @data.to_xml_string str
  if @f
    str << '</c:' << @ref_tag_name.to_s << '>'
  end
  str << '</c:' << tag_name.to_s << '>'
end