Class: Goldendocx::Parts::ContentTypes

Inherits:
Object
  • Object
show all
Includes:
Document
Defined in:
lib/goldendocx/parts/content_types.rb

Constant Summary collapse

XML_PATH =
'[Content_Types].xml'
NAMESPACE =
'http://schemas.openxmlformats.org/package/2006/content-types'
REQUIRED_DEFAULTS =
{
  rels: 'application/vnd.openxmlformats-package.relationships+xml',
  xml: 'application/xml'
}.with_indifferent_access.freeze

Instance Method Summary collapse

Methods included from Document

#to_document_xml

Methods included from Element

#build_element, #namespace, #tag, #tag_name, #to_element, #to_xml

Methods included from HasChildren

#children, #read_child, #read_children

Methods included from HasAttributes

#assign_attributes, #attributes, #read_attributes

Constructor Details

#initializeContentTypes

Returns a new instance of ContentTypes.



25
26
27
28
29
# File 'lib/goldendocx/parts/content_types.rb', line 25

def initialize
  REQUIRED_DEFAULTS.map do |extension, content_type|
    build_defaults(extension:, content_type:)
  end
end

Instance Method Details

#add_default(extension, content_type) ⇒ Object



36
37
38
39
40
# File 'lib/goldendocx/parts/content_types.rb', line 36

def add_default(extension, content_type)
  return if defaults.any? { |default| extension == default.extension && content_type == default.content_type }

  build_defaults(extension:, content_type:)
end

#add_override(part_name, content_type) ⇒ Object



42
43
44
45
46
# File 'lib/goldendocx/parts/content_types.rb', line 42

def add_override(part_name, content_type)
  return if overrides.any? { |override| part_name == override.part_name && content_type == override.content_type }

  build_override(part_name:, content_type:)
end

#write_to(zos) ⇒ Object



31
32
33
34
# File 'lib/goldendocx/parts/content_types.rb', line 31

def write_to(zos)
  zos.put_next_entry XML_PATH
  zos.write to_document_xml
end