Class: Axlsx::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/rels/relationship.rb

Overview

Note:

Packages automatically manage relationships.

A relationship defines a reference between package parts.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, target, options = {}) ⇒ Relationship

creates a new relationship

Parameters:

  • type (String)

    The type of the relationship

  • target (String)

    The target for the relationship

  • [Symbol] (Hash)

    a customizable set of options



36
37
38
39
40
# File 'lib/axlsx/rels/relationship.rb', line 36

def initialize(type, target, options={})
  self.Target=target
  self.Type=type
  self.TargetMode = options.delete(:target_mode) if options[:target_mode]
end

Instance Attribute Details

#TargetString

The location of the relationship target

Returns:

  • (String)


9
10
11
# File 'lib/axlsx/rels/relationship.rb', line 9

def Target
  @Target
end

#TargetModeObject

The target mode of the relationship used for hyperlink type relationships to mark the relationship to an external resource TargetMode can be specified during initialization by passing in a :target_mode option Target mode must be :external for now.



30
31
32
# File 'lib/axlsx/rels/relationship.rb', line 30

def TargetMode
  @TargetMode
end

#TypeString

Note:

Supported types are defined as constants in Axlsx:

The type of relationship



24
25
26
# File 'lib/axlsx/rels/relationship.rb', line 24

def Type
  @Type
end

Instance Method Details

#to_xml_string(rId, str = '') ⇒ String

serialize relationship

Parameters:

  • str (String) (defaults to: '')
  • rId (Integer)

    the id for this relationship

Returns:

  • (String)


54
55
56
57
58
59
60
# File 'lib/axlsx/rels/relationship.rb', line 54

def to_xml_string(rId, str = '')
  h = self.instance_values
  h[:Id] = 'rId' << rId.to_s
  str << '<Relationship '
  str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"'}.join(' ')
  str << '/>'
end