Class: Axlsx::TableStyle

Inherits:
SimpleTypedList show all
Defined in:
lib/axlsx/stylesheet/table_style.rb

Overview

Note:

Table are not supported in this version and only the defaults required for a valid workbook are created.

A single table style definition and is a collection for tableStyleElements

Instance Attribute Summary collapse

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(name, options = {}) ⇒ TableStyle

creates a new TableStyle object

Parameters:

  • name (String)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • pivot (Boolean)
  • table (Boolean)

Raises:

  • (ArgumentError)

    if name option is not provided.



23
24
25
26
27
28
29
# File 'lib/axlsx/stylesheet/table_style.rb', line 23

def initialize(name, options={})
  self.name = name
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
  end
  super TableStyleElement
end

Dynamic Method Handling

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

Instance Attribute Details

#namestring

The name of this table style

Returns:

  • (string)


8
9
10
# File 'lib/axlsx/stylesheet/table_style.rb', line 8

def name
  @name
end

#pivotBoolean

indicates if this style should be applied to pivot tables

Returns:

  • (Boolean)


12
13
14
# File 'lib/axlsx/stylesheet/table_style.rb', line 12

def pivot
  @pivot
end

#tableBoolean

indicates if this style should be applied to tables

Returns:

  • (Boolean)


16
17
18
# File 'lib/axlsx/stylesheet/table_style.rb', line 16

def table
  @table
end

Instance Method Details

#to_xml(xml) ⇒ String

Serializes the table style

Parameters:

  • xml (Nokogiri::XML::Builder)

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

Returns:

  • (String)


38
39
40
41
42
# File 'lib/axlsx/stylesheet/table_style.rb', line 38

def to_xml(xml)
  attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
  attr[:count] = self.size
  xml.tableStyle(attr) { self.each { |table_style_el| table_style_el.to_xml(xml) } }
end