summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb
blob: a242f0f8efe306648909c5eb260770a281742880 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
module Axlsx

  #A collection of hyperlink objects for a worksheet
  class WorksheetHyperlinks < SimpleTypedList

    # Creates a new Hyperlinks collection
    # @param [Worksheet] worksheet the worksheet that owns these hyperlinks
    def initialize(worksheet)
      DataTypeValidator.validate "Hyperlinks.worksheet", [Worksheet], worksheet
      @worksheet = worksheet
      super WorksheetHyperlink
    end

    # Creates and adds a new hyperlink based on the options provided
    # @see WorksheetHyperlink#initialize
    # @return [WorksheetHyperlink]
    def add(options)
      self << WorksheetHyperlink.new(@worksheet, options)
      last
    end

    # The relationships required by this collection's hyperlinks
    # @return Array
    def relationships
      return [] if empty?
      map { |hyperlink| hyperlink.relationship }
    end

    # seralize the collection of hyperlinks
    # @return [String]
    def to_xml_string(str='')
      return if empty?
      str << '<hyperlinks>'
      each { |hyperlink| hyperlink.to_xml_string(str) }
      str << '</hyperlinks>'
    end
  end
end