class OpenXml::Parts::Rels
Attributes
relationships[R]
Public Class Methods
new(defaults=[])
click to toggle source
# File lib/open_xml/parts/rels.rb, line 17 def initialize(defaults=[]) @relationships = [] Array(defaults).each do |default| add_relationship(*default.values_at("Type", "Target", "Id")) end end
parse(xml)
click to toggle source
# File lib/open_xml/parts/rels.rb, line 8 def self.parse(xml) document = Nokogiri(xml) self.new.tap do |part| document.css("Relationship").each do |rel| part.add_relationship rel["Type"], rel["Target"], rel["Id"] end end end
Public Instance Methods
add_relationship(type, target, id=nil)
click to toggle source
# File lib/open_xml/parts/rels.rb, line 24 def add_relationship(type, target, id=nil) Relationship.new(type, target, id).tap do |relationship| relationships.push relationship end end
each(&block)
click to toggle source
# File lib/open_xml/parts/rels.rb, line 30 def each(&block) relationships.each(&block) end
to_xml()
click to toggle source
# File lib/open_xml/parts/rels.rb, line 34 def to_xml build_standalone_xml do |xml| xml.Relationships(xmlns: "http://schemas.openxmlformats.org/package/2006/relationships") do relationships.each do |rel| xml.Relationship("Id" => rel.id, "Type" => rel.type, "Target" => rel.target) end end end end