Sha256: 469bd830b5f59159c172ce11f629fb819d0eca87f24bb2c0e3113c28ca4124fc

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

module Axlsx
  # An axis data source that can contain referenced or literal strings or numbers
  # @note only string data types are supported - mainly because we have not implemented a chart type that requires a numerical axis value
  class AxDataSource

    # 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
      [:xVal, :cat]
    end

    # 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={})
      @f = nil
      @tag_name = :cat
      @data = StrData.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

    # sets the tag name for this data source
    # @param [Symbol] 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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
axlsx-1.1.7 lib/axlsx/drawing/ax_data_source.rb~
axlsx-1.1.6 lib/axlsx/drawing/ax_data_source.rb~
axlsx-1.1.5 lib/axlsx/drawing/ax_data_source.rb~
axlsx-1.1.4 lib/axlsx/drawing/ax_data_source.rb~