Class: Axlsx::WorksheetHyperlinks

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

Overview

A collection of hyperlink objects for a worksheet

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ WorksheetHyperlinks

Creates a new Hyperlinks collection

Parameters:

  • worksheet (Worksheet)

    the worksheet that owns these hyperlinks



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

def initialize(worksheet)
  DataTypeValidator.validate "Hyperlinks.worksheet", [Worksheet], worksheet
  @worksheet = worksheet
  super(WorksheetHyperlink)
end

Instance Method Details

#add(options) ⇒ WorksheetHyperlink

Creates and adds a new hyperlink based on the options provided



17
18
19
20
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb', line 17

def add(options)
  self << WorksheetHyperlink.new(@worksheet, options)
  last
end

#relationshipsObject

The relationships required by this collection's hyperlinks

Returns:

  • Array



24
25
26
27
28
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb', line 24

def relationships
  return [] if empty?

  map(&:relationship)
end

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

seralize the collection of hyperlinks

Returns:

  • (String)


32
33
34
35
36
37
38
# File 'lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb', line 32

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

  str << '<hyperlinks>'
  each { |hyperlink| hyperlink.to_xml_string(str) }
  str << '</hyperlinks>'
end