Sha256: 9fff16a8aa85ae2667adf0a739cde48efe6088613e11fa96b95ef9bebd1e032a

Contents?: true

Size: 1.69 KB

Versions: 40

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require_relative 'relationships/relationship'
module OoxmlParser
  # Class for describing list of relationships
  class Relationships < OOXMLDocumentObject
    # @return [Array, Relationship] array of relationships
    attr_accessor :relationship

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

    # @return [Array, Column] accessor for relationship
    def [](key)
      @relationship[key]
    end

    # Parse Relationships
    # @param [Nokogiri::XML:Node] node with Relationships
    # @return [Relationships] result of parsing
    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 .rels file
    # @param file_path [String] path to file
    # @return [Relationships]
    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

    # Get target name by id
    # @param id [String] id of target
    # @return [String] target name
    def target_by_id(id)
      @relationship.each do |cur_rels|
        return cur_rels.target if cur_rels.id == id
      end
      nil
    end

    # Get target names by type
    # @param type [String] type of target
    # @return [Array<String>] target names
    def target_by_type(type)
      result = []
      @relationship.each do |cur_rels|
        result << cur_rels.target if cur_rels.type.include?(type)
      end
      result
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ooxml_parser-0.21.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.20.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.19.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.18.1 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.18.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.17.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.16.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.15.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.14.2 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.14.1-mingw32 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.14.1 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.14.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.13.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.12.2 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.12.1 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.12.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.11.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.10.0 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.9.1 lib/ooxml_parser/common_parser/common_data/relationships.rb
ooxml_parser-0.9.0 lib/ooxml_parser/common_parser/common_data/relationships.rb