Class: OoxmlParser::Relationships
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Relationships
- Defined in:
- lib/ooxml_parser/common_parser/common_data/relationships.rb
Overview
Class for describing list of relationships
Instance Attribute Summary collapse
-
#relationship ⇒ Array, Relationship
Array of relationships.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#[](key) ⇒ Array, Column
Accessor for relationship.
-
#initialize(parent: nil) ⇒ Relationships
constructor
A new instance of Relationships.
-
#parse(node) ⇒ Relationships
Parse Relationships.
-
#parse_file(file_path) ⇒ Relationships
Parse .rels file.
-
#target_by_id(id) ⇒ String
Get target name by id.
-
#target_by_type(type) ⇒ Array<String>
Get target names by type.
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
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
#relationship ⇒ Array, Relationship
Returns array of relationships.
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.
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
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
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
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
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 |