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



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

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



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

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

#relationshipsObject

The relationships required by this collection's hyperlinks

Returns:

  • Array



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

def relationships
  return [] if empty?

  map { |hyperlink| hyperlink.relationship }
end

#to_xml_string(str = '') ⇒ String

seralize the collection of hyperlinks

Returns:

  • (String)


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

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

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