Class: RubyXL::OOXMLRelationshipsFile

Inherits:
OOXMLTopLevelObject show all
Defined in:
lib/rubyXL/objects/relationships.rb

Constant Summary collapse

@@debug =

Change to 0 to enable debug output

nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLTopLevelObject

#add_to_zip, #file_index, parse_file, set_namespaces

Methods included from OOXMLObjectClassMethods

#define_attribute, #define_child_node, #define_element_name, #obtain_class_variable, #parse, #set_countable

Methods included from OOXMLObjectInstanceMethods

#before_write_xml, #dup, #index_in_collection, #initialize, #write_xml

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



22
23
24
# File 'lib/rubyXL/objects/relationships.rb', line 22

def owner
  @owner
end

Returns the value of attribute related_files.



22
23
24
# File 'lib/rubyXL/objects/relationships.rb', line 22

def related_files
  @related_files
end

Class Method Details

.get_class_by_rel_type(rel_type) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubyXL/objects/relationships.rb', line 53

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) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/rubyXL/objects/relationships.rb', line 101

def self.load_relationship_file(zipdir_path, base_file_path)
  rel_file_path = Pathname.new(File.join(File.dirname(base_file_path), '_rels', File.basename(base_file_path) + '.rels')).cleanpath

  puts "--> DEBUG:  #{'  ' * @@debug}Loading .rel file: #{rel_file_path}" if @@debug

  parse_file(zipdir_path, rel_file_path)
end

.save_orderObject



41
42
43
# File 'lib/rubyXL/objects/relationships.rb', line 41

def self.save_order
  0
end

Instance Method Details

#find_by_rid(r_id) ⇒ Object



45
46
47
# 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) ⇒ Object



49
50
51
# File 'lib/rubyXL/objects/relationships.rb', line 49

def find_by_target(target)
  relationships.find { |r| r.target == target }
end


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rubyXL/objects/relationships.rb', line 68

def load_related_files(zipdir_path, base_file_name = '')
  self.related_files = {}

  @@debug +=2 if @@debug

  self.relationships.each { |rel|
    next if rel.target_mode == 'External'

    file_path = Pathname.new(rel.target)

    if !file_path.absolute? then
      file_path = (Pathname.new(File.dirname(base_file_name)) + file_path).cleanpath
    end

    klass = RubyXL::OOXMLRelationshipsFile.get_class_by_rel_type(rel.type)

    if klass.nil? then
      puts "*** WARNING: storage class not found for #{rel.target} (#{rel.type})"
      klass = GenericStorageObject
    end

    puts "--> DEBUG:#{'  ' * @@debug}Loading #{klass} (#{rel.id}): #{file_path}" if @@debug

    obj = klass.parse_file(zipdir_path, file_path)
    obj.load_relationships(zipdir_path, file_path) if obj.respond_to?(:load_relationships)
    self.related_files[rel.id] = obj
  }

  @@debug -=2 if @@debug

  related_files
end

#xlsx_pathObject



109
110
111
112
# File 'lib/rubyXL/objects/relationships.rb', line 109

def xlsx_path
  file_path = owner.xlsx_path
  File.join(File.dirname(file_path), '_rels', File.basename(file_path) + '.rels')
end