Class: Uniword::Docx::Part
- Inherits:
-
Object
- Object
- Uniword::Docx::Part
- Defined in:
- lib/uniword/docx/part.rb
Overview
Value object for one package-held part (chart, embedding, header, footer, ...).
A Part couples the part's content (a lutaml-model object or a raw String) with the packaging metadata the OPC layer needs to emit it: relationship target, relationship id, content type and relationship type. Defaults for the metadata come from the part's Ooxml::PartDefinition (the single source of truth); loaded documents may carry verbatim overrides (e.g. strict-OOXML relationship URIs).
Replaces the raw Hash entries previously stored in
chart_parts, embeddings and header_footer_parts. Hash-style
read access (+part+) is kept for backward compatibility.
Direct Known Subclasses
Constant Summary collapse
- HASH_LOOKUP =
Key → reader lambdas backing hash-style access (kept as data so the dispatch stays declarative).
{ r_id: lambda(&:r_id), target: lambda(&:target), rel_type: lambda(&:rel_type), content_type: lambda(&:content_type), content: lambda(&:content), path: lambda(&:path), }.freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
Part content (model object or raw String).
-
#content_type ⇒ String?
MIME content type.
-
#definition ⇒ Ooxml::PartDefinition?
readonly
Registry definition for this part kind.
-
#r_id ⇒ String?
Relationship id (nil until wired).
-
#rel_type ⇒ String?
Relationship type URI.
-
#target ⇒ String?
Relationship target relative to word/.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Hash-style read compatibility for former hash entries.
-
#initialize(definition: nil, r_id: nil, target: nil, content: nil, rel_type: nil, content_type: nil) ⇒ Part
constructor
rubocop:disable Metrics/ParameterLists.
-
#path ⇒ String?
Package-relative path of the emitted part.
Constructor Details
#initialize(definition: nil, r_id: nil, target: nil, content: nil, rel_type: nil, content_type: nil) ⇒ Part
rubocop:disable Metrics/ParameterLists
52 53 54 55 56 57 58 59 60 |
# File 'lib/uniword/docx/part.rb', line 52 def initialize(definition: nil, r_id: nil, target: nil, content: nil, rel_type: nil, content_type: nil) @definition = definition @r_id = r_id @target = target @content = content @rel_type = rel_type @content_type = content_type end |
Instance Attribute Details
#content ⇒ Object
Returns part content (model object or raw String).
40 41 42 |
# File 'lib/uniword/docx/part.rb', line 40 def content @content end |
#content_type ⇒ String?
Returns MIME content type.
69 70 71 |
# File 'lib/uniword/docx/part.rb', line 69 def content_type @content_type || definition&.content_type end |
#definition ⇒ Ooxml::PartDefinition? (readonly)
Returns registry definition for this part kind.
31 32 33 |
# File 'lib/uniword/docx/part.rb', line 31 def definition @definition end |
#r_id ⇒ String?
Returns relationship id (nil until wired).
34 35 36 |
# File 'lib/uniword/docx/part.rb', line 34 def r_id @r_id end |
#rel_type ⇒ String?
Returns relationship type URI.
64 65 66 |
# File 'lib/uniword/docx/part.rb', line 64 def rel_type @rel_type || definition&.rel_type end |
#target ⇒ String?
Returns relationship target relative to word/.
37 38 39 |
# File 'lib/uniword/docx/part.rb', line 37 def target @target end |
Instance Method Details
#[](key) ⇒ Object?
Hash-style read compatibility for former hash entries.
101 102 103 |
# File 'lib/uniword/docx/part.rb', line 101 def [](key) HASH_LOOKUP[key.to_sym]&.call(self) end |
#path ⇒ String?
Package-relative path of the emitted part. Document-scoped parts live under word/; their target is already relative to word/.
78 79 80 |
# File 'lib/uniword/docx/part.rb', line 78 def path target && "word/#{target}" end |