Class: Axlsx::Relationship

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

Overview

Note:

Packages automatcially 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



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

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)


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

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.



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

def TargetMode
  @TargetMode
end

#TypeString

Note:

Supported types are defined as constants in Axlsx:

The type of relationship



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

def Type
  @Type
end

Instance Method Details

#to_xml(xml, rId) ⇒ String

Serializes the relationship

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

  • rId (String)

    the reference id of the object.

Returns:

  • (String)


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

def to_xml(xml, rId)
  h = self.instance_values
  h[:Id] = rId
  xml.Relationship(h)
end