Class: Axlsx::CatAxisData

Inherits:
SimpleTypedList show all
Defined in:
lib/axlsx/drawing/cat_axis_data.rb

Overview

The CatAxisData class serializes the category axis data for a chart

Direct Known Subclasses

ValAxisData

Instance Attribute Summary

Attributes inherited from SimpleTypedList

#allowed_types, #locked_at, #serialize_as

Instance Method Summary collapse

Methods inherited from SimpleTypedList

#<<, #==, #[]=, #delete, #delete_at, #lock, #method_missing, #protected?, #push, #unlock

Constructor Details

#initialize(data = []) ⇒ CatAxisData

Create a new CatAxisData object

Parameters:

  • data (Array, SimpleTypedList) (defaults to: [])

    the data for this category axis. This can be a simple array or a simple typed list of cells.



7
8
9
10
# File 'lib/axlsx/drawing/cat_axis_data.rb', line 7

def initialize(data=[])
  super Object
  @list.concat data if data.is_a?(Array)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Axlsx::SimpleTypedList

Instance Method Details

#to_xml(xml) ⇒ String

Serializes the category axis data

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/axlsx/drawing/cat_axis_data.rb', line 15

def to_xml(xml)
  xml.send('c:cat') {
    xml.send('c:strRef') {
      xml.send('c:f', Axlsx::cell_range(@list))
      xml.send('c:strCache') {
        xml.send('c:ptCount', :val=>size)
        each_with_index do |item, index|
          v = item.is_a?(Cell) ? item.value : item
          xml.send('c:pt', :idx=>index) {
            xml.send('c:v', v)
          }                          
        end
      }
    }
  }
end