Class: Axlsx::Tables

Inherits:
SimpleTypedList
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/tables.rb

Overview

A simple, self serializing class for storing tables

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ Tables

creates a new Tables object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/axlsx/workbook/worksheet/tables.rb', line 7

def initialize(worksheet)
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)

  super(Table)
  @worksheet = worksheet
end

Instance Attribute Details

#worksheetWorksheet (readonly)

The worksheet that owns this collection of tables

Returns:



16
17
18
# File 'lib/axlsx/workbook/worksheet/tables.rb', line 16

def worksheet
  @worksheet
end

Instance Method Details

#relationshipsObject

returns the relationships required by this collection



19
20
21
22
23
# File 'lib/axlsx/workbook/worksheet/tables.rb', line 19

def relationships
  return [] if empty?

  map { |table| Relationship.new(table, TABLE_R, "../#{table.pn}") }
end

#to_xml_string(str = +'')) ⇒ String

renders the tables xml

Parameters:

  • str (String) (defaults to: +''))

Returns:

  • (String)


28
29
30
31
32
33
34
# File 'lib/axlsx/workbook/worksheet/tables.rb', line 28

def to_xml_string(str = +'')
  return if empty?

  str << "<tableParts count='#{size}'>"
  each { |table| str << "<tablePart r:id='#{table.rId}'/>" }
  str << '</tableParts>'
end