Sha256: f975701f23af85cbcc13c6b9f676f9b853b1d25fcee49753f8095caa0ce7f840

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

# -*- coding: utf-8 -*-
module Axlsx

  #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
  class StrData

    def self.allowed_tag_names
      [:strCache, :strLit]
    end

    # A list of NumVal objects
    # @return [SimpleTypedList]
    attr_reader :pt

    # The tag name to use when serializing this object.
    # this is restricted to the values returnd by self.allowed_tag_names
    attr_reader :tag_name

    # creates a new StrVal object
    # @option options [Array] :data
    # @option options [String] :tag_name
    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

    def data=(values)
     # raise ArgumentError, 'data assignation must be done with an array' unless values.is_a?(Array)
      @tag_name = values.first.is_a?(Cell) ? "#{@tag_prefix.to_s}Cache".to_sym : "#{@tag_prefix.to_s}Lit".to_sym
      values.each do |value|
        v = value.is_a?(Cell)? v.value : value
        @pt << @type.new(:v => v)
      end
    end

    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
    def to_xml_string(idx, 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

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

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