Module: OpenXml::RelatablePart

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



27
28
29
# File 'lib/openxml/pptx/relatable_part.rb', line 27

def parent
  @parent
end

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/openxml/pptx/relatable_part.rb', line 4

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#add_child_part(part, with_index: nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/openxml/pptx/relatable_part.rb', line 67

def add_child_part(part, with_index: nil)
  part.path = indexed_path(part.path, with_index) unless with_index.nil?
  part.parent = self if part.respond_to?(:parent=)
  add_relationship part.relationship_type, part.path
  return unless instance_variable_defined?("@parent")
  add_part part.path, part
  if part.respond_to?(:relationships_path) && !part.relationships_path.nil?
    rel_path = with_index.nil? ? part.relationships_path : indexed_path(part.relationships_path, with_index)
    add_part rel_path, part.relationships
  end
  add_override part.path, part.content_type if part.respond_to?(:content_type)
end

#add_override(part_path, content_type) ⇒ Object



84
85
86
# File 'lib/openxml/pptx/relatable_part.rb', line 84

def add_override(part_path, content_type)
  parent.add_override part_path, content_type
end

#add_part(part_path, part) ⇒ Object



80
81
82
# File 'lib/openxml/pptx/relatable_part.rb', line 80

def add_part(part_path, part)
  parent.add_part part_path.to_s, part
end

#add_relationship(type, part_path) ⇒ Object



88
89
90
91
# File 'lib/openxml/pptx/relatable_part.rb', line 88

def add_relationship(type, part_path)
  relationship = relationships.add_relationship type, Pathname.new(part_path).relative_path_from(path.dirname)
  relationships_by_path[part_path] = relationship
end

#content_typeObject



50
51
52
# File 'lib/openxml/pptx/relatable_part.rb', line 50

def content_type
  self.class.content_type
end

#file_nameObject



46
47
48
# File 'lib/openxml/pptx/relatable_part.rb', line 46

def file_name
  self.class.default_path.basename
end

#indexed_path(part_path, index) ⇒ Object



93
94
95
96
97
# File 'lib/openxml/pptx/relatable_part.rb', line 93

def indexed_path(part_path, index)
  extension = part_path.to_s.match(/\w(\..+)$/)[1]
  path_without_extension = part_path.to_s[0...-extension.length]
  Pathname.new("#{path_without_extension}#{index}#{extension}")
end

#initialize(parent: nil, **_options) ⇒ Object



29
30
31
32
# File 'lib/openxml/pptx/relatable_part.rb', line 29

def initialize(parent: nil, **_options)
  @parent = parent
  super()
end

#pathObject



54
55
56
# File 'lib/openxml/pptx/relatable_part.rb', line 54

def path
  @path || Pathname.new("#{self.class.default_path.dirname}/#{file_name}")
end

#path=(value) ⇒ Object



58
59
60
# File 'lib/openxml/pptx/relatable_part.rb', line 58

def path=(value)
  @path = Pathname.new(value)
end

#relationship_typeObject



42
43
44
# File 'lib/openxml/pptx/relatable_part.rb', line 42

def relationship_type
  self.class.relationship_type
end

#relationshipsObject



34
35
36
# File 'lib/openxml/pptx/relatable_part.rb', line 34

def relationships
  @relationships ||= OpenXml::Parts::Rels.new
end

#relationships_by_pathObject



38
39
40
# File 'lib/openxml/pptx/relatable_part.rb', line 38

def relationships_by_path
  @relationships_by_path ||= {}
end

#relationships_pathObject



62
63
64
65
# File 'lib/openxml/pptx/relatable_part.rb', line 62

def relationships_path
  directory = self.class.default_path.dirname
  "#{directory}/_rels/#{file_name}.rels"
end