summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/pivot_tables.rb
blob: 7ba09b091dd2b63c3ca197d3199028a51962f505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module Axlsx
  # A simple, self serializing class for storing pivot tables
  class PivotTables < SimpleTypedList
    # creates a new Tables object
    def initialize(worksheet)
      raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)

      super PivotTable
      @worksheet = worksheet
    end

    # The worksheet that owns this collection of pivot tables
    # @return [Worksheet]
    attr_reader :worksheet

    # returns the relationships required by this collection
    def relationships
      return [] if empty?

      map { |pivot_table| Relationship.new(pivot_table, PIVOT_TABLE_R, "../#{pivot_table.pn}") }
    end
  end
end