Sha256: 7d6a1c4a6334081fde62afab3597c0ae1bdee190582aa6ce76c52b09d2672c06

Contents?: true

Size: 1.59 KB

Versions: 17

Compression:

Stored size: 1.59 KB

Contents

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

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

    include Axlsx::OptionsParser

    # creates a new NumVal object
    # @option options [String] formatCode
    # @option options [Array] :data
    # @see StrData
    def initialize(options={})
      @format_code = "General"
      @pt = SimpleTypedList.new NumVal
      parse_options options
    end

    # A string representing the format code to apply. For more information see see the SpreadsheetML numFmt element's (ยง18.8.30) formatCode attribute.
    # @return [String]
    attr_reader :format_code

    # Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
    # @param [Array] values An array of cells or values.
    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

    # @see format_code
    def format_code=(v='General')
      Axlsx::validate_string(v)
      @format_code = v
    end

    # serialize the object
    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

  end

end

Version data entries

17 entries across 17 versions & 6 rubygems

Version Path
caxlsx-3.3.0 lib/axlsx/drawing/num_data.rb
caxlsx-3.1.1 lib/axlsx/drawing/num_data.rb
caxlsx-3.1.0 lib/axlsx/drawing/num_data.rb
bonio-axlsx-2.2.3 lib/axlsx/drawing/num_data.rb
caxlsx-3.0.4 lib/axlsx/drawing/num_data.rb
caxlsx-3.0.3 lib/axlsx/drawing/num_data.rb
caxlsx-3.0.2 lib/axlsx/drawing/num_data.rb
caxlsx-3.0.1 lib/axlsx/drawing/num_data.rb
caxlsx-3.0.0 lib/axlsx/drawing/num_data.rb
axlsx-alt-3.0.1 lib/axlsx/drawing/num_data.rb
axlsx-alt-3.0.0 lib/axlsx/drawing/num_data.rb
axlsx-3.0.0.pre lib/axlsx/drawing/num_data.rb
bonio-axlsx-2.2.2 lib/axlsx/drawing/num_data.rb
bonio-axlsx-2.2.1 lib/axlsx/drawing/num_data.rb
dg-axlsx-2.1.0 lib/axlsx/drawing/num_data.rb
axlsx-2.1.0.pre lib/axlsx/drawing/num_data.rb
l_axlsx-2.0.1 lib/axlsx/drawing/num_data.rb