Sha256: a6f517a47f7741b8fc20f2c40d9ccda0b4009d060c6ee513c925568b1a171534

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Axlsx
  # A numeric data source for use by charts.
  class NumDataSource
    include Axlsx::OptionsParser

    # creates a new NumDataSource object
    # @option options [Array] data An array of Cells or Numeric objects
    # @option options [Symbol] tag_name see tag_name
    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
      parse_options options
    end

    # The tag name to use when serializing this data source.
    # Only items defined in allowed_tag_names are allowed
    # @return [Symbol]
    attr_reader :tag_name

    attr_reader :data

    # allowed element tag names
    # @return [Array]
    def self.allowed_tag_names
      [:yVal, :val, :bubbleSize]
    end

    # sets the tag name for this data source
    # @param [Symbol] v One of the allowed_tag_names
    def tag_name=(v)
      Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
      @tag_name = v
    end

    # serialize the object
    # @param [String] str
    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
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
caxlsx-4.2.0 lib/axlsx/drawing/num_data_source.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/caxlsx-4.1.0/lib/axlsx/drawing/num_data_source.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/caxlsx-4.1.0/lib/axlsx/drawing/num_data_source.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/caxlsx-4.1.0/lib/axlsx/drawing/num_data_source.rb
caxlsx-4.1.0 lib/axlsx/drawing/num_data_source.rb
caxlsx-4.0.0 lib/axlsx/drawing/num_data_source.rb