Class: OoxmlParser::Relationships

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/relationships.rb

Overview

Class for describing list of relationships

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ Relationships

Returns a new instance of Relationships.



10
11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/relationships.rb', line 10

def initialize(parent: nil)
  @relationship = []
  super
end

Instance Attribute Details

#relationshipArray, Relationship

Returns array of relationships.

Returns:



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/relationships.rb', line 8

def relationship
  @relationship
end

Instance Method Details

#[](key) ⇒ Array, Column

Returns accessor for relationship.

Returns:

  • (Array, Column)

    accessor for relationship



16
17
18
# File 'lib/ooxml_parser/common_parser/common_data/relationships.rb', line 16

def [](key)
  @relationship[key]
end

#parse(node) ⇒ Relationships

Parse Relationships

Parameters:

  • node (Nokogiri::XML:Node)

    with Relationships

Returns:



23
24
25
26
27
28
29
30
31
# File 'lib/ooxml_parser/common_parser/common_data/relationships.rb', line 23

def parse(node)
  node.xpath('*').each do |node_children|
    case node_children.name
    when 'Relationship'
      @relationship << Relationship.new(parent: self).parse(node_children)
    end
  end
  self
end

#parse_file(file_path) ⇒ Relationships

Parse .rels file

Parameters:

  • file_path (String)

    path to file

Returns:



36
37
38
39
40
41
42
43
44
45
# File 'lib/ooxml_parser/common_parser/common_data/relationships.rb', line 36

def parse_file(file_path)
  node = parse_xml(file_path)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'Relationships'
      parse(node_child)
    end
  end
  self
end

#target_by_id(id) ⇒ String

Get target name by id

Parameters:

  • id (String)

    id of target

Returns:

  • (String)

    target name



50
51
52
53
54
55
# File 'lib/ooxml_parser/common_parser/common_data/relationships.rb', line 50

def target_by_id(id)
  @relationship.each do |cur_rels|
    return cur_rels.target if cur_rels.id == id
  end
  nil
end

#target_by_type(type) ⇒ Array<String>

Get target names by type

Parameters:

  • type (String)

    type of target

Returns:

  • (Array<String>)

    target names



60
61
62
63
64
65
66
# File 'lib/ooxml_parser/common_parser/common_data/relationships.rb', line 60

def target_by_type(type)
  result = []
  @relationship.each do |cur_rels|
    result << cur_rels.target if cur_rels.type.include?(type)
  end
  result
end