class RubyXL::OOXMLRelationshipsFile
Constants
- CONTENT_TYPE
- SAVE_ORDER
Attributes
owner[RW]
Public Class Methods
get_class_by_rel_type(rel_type)
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 55 def self.get_class_by_rel_type(rel_type) unless defined?(@@rel_hash) @@rel_hash = {} RubyXL.constants.each { |c| klass = RubyXL.const_get(c) if klass.is_a?(Class) && klass.const_defined?(:REL_TYPE) then @@rel_hash[klass::REL_TYPE] = klass end } end @@rel_hash[rel_type] end
load_relationship_file(zipdir_path, base_file_path)
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 100 def self.load_relationship_file(zipdir_path, base_file_path) rel_file_path = rel_file_path(base_file_path) puts "--> DEBUG: #{' ' * @@debug}Loading .rel file: #{rel_file_path}" if @@debug parse_file(zipdir_path, rel_file_path) end
rel_file_path(base_file_path)
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 126 def self.rel_file_path(base_file_path) basename = base_file_path.root? ? '' : base_file_path.basename base_file_path.dirname.join('_rels', "#{basename}.rels").cleanpath end
Public Instance Methods
before_write_xml()
click to toggle source
Calls superclass method
RubyXL::OOXMLObjectInstanceMethods#before_write_xml
# File lib/rubyXL/objects/relationships.rb, line 112 def before_write_xml case owner when RubyXL::WorkbookRoot, RubyXL::Workbook then # Fully implemented objects with no generic (unhandled) relationships - # (re)generating relationships from scratch. related_objects = owner.related_objects related_objects += owner.generic_storage if owner.generic_storage self.relationships = [] related_objects.compact.each { |f| add_relationship(f) } end super end
find_by_rid(r_id)
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 45 def find_by_rid(r_id) relationships.find { |r| r.id == r_id } end
find_by_target(target)
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 49 def find_by_target(target) relationships.find { |r| (r.target == target) || (r.target == target.relative_path_from(owner.xlsx_path.dirname)) } end
xlsx_path()
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 108 def xlsx_path self.class.rel_file_path(owner.xlsx_path) end
Protected Instance Methods
add_relationship(obj)
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 37 def add_relationship(obj) return if obj.nil? || !defined?(obj.class::REL_TYPE) relationships << RubyXL::Relationship.new(:id => "rId#{relationships.size + 1}", :type => obj.class::REL_TYPE, :target => obj.xlsx_path.relative_path_from(owner.xlsx_path.dirname)) end
new_relationship(target, type)
click to toggle source
# File lib/rubyXL/objects/relationships.rb, line 30 def new_relationship(target, type) RubyXL::Relationship.new(:id => "rId#{relationships.size + 1}", :type => type, :target => target) end