Class: Uniword::Docx::RawPart

Inherits:
Part
  • Object
show all
Defined in:
lib/uniword/docx/raw_part.rb

Overview

A package part no Ooxml::PartDefinition models, carried verbatim for round-trip fidelity (e.g. docProps/meta.xml, glossary documents, VBA projects, unmodelled .rels sidecars).

Unlike document-scoped parts (charts, images, embeddings), a raw part keeps its full package-relative path — raw parts live anywhere in the package, not only under word/. Content is the exact source byte stream (binary-safe; never parsed or re-encoded), plus the content type the source [Content_Types].xml declared for it (Override first, then Default by extension; nil when the source declared neither).

The relationship referencing the part (when one exists in a modelled .rels part) is recorded as +r_id+/+rel_type+ metadata for introspection parity with other part kinds; emission never uses it — relationships re-serialize from the loaded rels models, so the source rel survives untouched.

Raw parts are a fallback: PartLoader claims every registry-known path first and RawPartLoader carries only the remainder, so a part is never emitted twice.

Examples:

part = RawPart.new(
  path: "docProps/meta.xml",
  content: bytes,
  content_type: "application/xml",
)
part.package_paths # => ["docProps/meta.xml"]

Constant Summary

Constants inherited from Part

Part::HASH_LOOKUP

Instance Attribute Summary collapse

Attributes inherited from Part

#content, #content_type, #definition, #r_id, #rel_type, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Part

#[], #package_paths

Constructor Details

#initialize(path: nil, content: nil, content_type: nil, r_id: nil, rel_type: nil) ⇒ RawPart

Returns a new instance of RawPart.

Parameters:

  • path (String, nil) (defaults to: nil)

    package-relative path (e.g. "docProps/meta.xml")

  • content (String, nil) (defaults to: nil)

    raw part bytes (binary-safe)

  • content_type (String, nil) (defaults to: nil)

    content type declared by the source [Content_Types].xml

  • r_id (String, nil) (defaults to: nil)

    id of the relationship referencing this part (metadata only)

  • rel_type (String, nil) (defaults to: nil)

    type of the relationship referencing this part (metadata only)



47
48
49
50
51
52
# File 'lib/uniword/docx/raw_part.rb', line 47

def initialize(path: nil, content: nil, content_type: nil,
               r_id: nil, rel_type: nil)
  super(content: content, content_type: content_type,
        r_id: r_id, rel_type: rel_type)
  @path = path
end

Instance Attribute Details

#pathString?

Package-relative path of the emitted part, carried verbatim (overrides Part's word/-prefixed target derivation).

Returns:

  • (String, nil)

    e.g. "word/glossary/document.xml"



70
71
72
# File 'lib/uniword/docx/raw_part.rb', line 70

def path
  @path
end

Class Method Details

.from_hash(hash) ⇒ RawPart

Wrap a raw-hash entry ({ path:, content:, content_type: }) into a RawPart. Used by PartCollection to normalize hash assignments.

Parameters:

  • hash (Hash)

    raw hash entry

Returns:



60
61
62
63
64
# File 'lib/uniword/docx/raw_part.rb', line 60

def self.from_hash(hash)
  new(path: hash[:path], content: hash[:content],
      content_type: hash[:content_type],
      r_id: hash[:r_id], rel_type: hash[:rel_type])
end