Class: Uniword::Ooxml::PartDefinition
- Inherits:
-
Object
- Object
- Uniword::Ooxml::PartDefinition
- Defined in:
- lib/uniword/ooxml/part_definition.rb
Overview
Declarative description of one OOXML package part kind.
A PartDefinition is the single source of truth for a part's package path, content type, relationship type, and the form its [Content_Types].xml entry takes (Default by extension or Override by part name). Instances are immutable value objects registered in PartRegistry; consumers derive every literal from them.
Parts with instance-numbered paths (headers, footers, charts,
customXml items) carry a +path_pattern+/+target_pattern+ with
+format+-style placeholders (e.g. "word/header%
Instance Attribute Summary collapse
-
#content_type ⇒ String?
readonly
MIME content type (nil when dynamic, e.g. images whose type depends on the file extension).
-
#extension ⇒ String?
readonly
File extension for Default entries.
-
#key ⇒ Symbol
readonly
Unique registry key (e.g. :styles).
-
#kind ⇒ Symbol
readonly
:override, :default, or :none (no [Content_Types].xml entry of its own).
-
#path ⇒ String?
readonly
Package-relative path ("word/styles.xml").
-
#path_pattern ⇒ String?
readonly
Path template for instance-numbered parts.
-
#rel_type ⇒ String?
readonly
Relationship type URI (nil when the part is not referenced by a relationship).
-
#rels_scope ⇒ Symbol?
readonly
:package or :document — which .rels part the relationship lives in (nil when
rel_typeis nil). -
#required ⇒ Boolean
readonly
Whether a minimal valid package carries it.
-
#standard ⇒ Boolean
readonly
Whether ContentTypes.generate includes it in the comprehensive [Content_Types].xml for new DOCX packages.
-
#target ⇒ String?
readonly
Relationship Target as written in .rels (relative to the owning part; defaults to
path). -
#target_pattern ⇒ String?
readonly
Target template for numbered parts.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two definitions are equal when every field matches.
-
#default? ⇒ Boolean
True for [Content_Types].xml Default entries.
-
#initialize(key:, kind:, path: nil, path_pattern: nil, target: nil, target_pattern: nil, content_type: nil, rel_type: nil, extension: nil, required: false, rels_scope: nil, standard: false) ⇒ PartDefinition
constructor
rubocop:disable Metrics/ParameterLists.
-
#override? ⇒ Boolean
True for [Content_Types].xml Override entries.
-
#package_rel? ⇒ Boolean
True when the relationship lives in _rels/.rels.
-
#part_name ⇒ String?
Fixed-path Override part name (leading slash).
-
#part_name_for(**vars) ⇒ String?
Resolve the content-type Override part name (leading slash).
-
#path_for(**vars) ⇒ String?
Resolve the package-relative path, interpolating pattern placeholders for instance-numbered parts.
-
#required? ⇒ Boolean
True when a minimal valid package carries it.
-
#standard? ⇒ Boolean
True when ContentTypes.generate includes it.
-
#target_for(**vars) ⇒ String?
Resolve the relationship Target attribute.
Constructor Details
#initialize(key:, kind:, path: nil, path_pattern: nil, target: nil, target_pattern: nil, content_type: nil, rel_type: nil, extension: nil, required: false, rels_scope: nil, standard: false) ⇒ PartDefinition
rubocop:disable Metrics/ParameterLists
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/uniword/ooxml/part_definition.rb', line 69 def initialize(key:, kind:, path: nil, path_pattern: nil, target: nil, target_pattern: nil, content_type: nil, rel_type: nil, extension: nil, required: false, rels_scope: nil, standard: false) @key = key.to_sym @kind = kind @path = path @path_pattern = path_pattern @target = target || path @target_pattern = target_pattern @content_type = content_type @rel_type = rel_type @extension = extension @required = required @rels_scope = rels_scope @standard = standard end |
Instance Attribute Details
#content_type ⇒ String? (readonly)
Returns MIME content type (nil when dynamic, e.g. images whose type depends on the file extension).
44 45 46 |
# File 'lib/uniword/ooxml/part_definition.rb', line 44 def content_type @content_type end |
#extension ⇒ String? (readonly)
Returns file extension for Default entries.
51 52 53 |
# File 'lib/uniword/ooxml/part_definition.rb', line 51 def extension @extension end |
#key ⇒ Symbol (readonly)
Returns unique registry key (e.g. :styles).
27 28 29 |
# File 'lib/uniword/ooxml/part_definition.rb', line 27 def key @key end |
#kind ⇒ Symbol (readonly)
Returns :override, :default, or :none (no [Content_Types].xml entry of its own).
58 59 60 |
# File 'lib/uniword/ooxml/part_definition.rb', line 58 def kind @kind end |
#path ⇒ String? (readonly)
Returns package-relative path ("word/styles.xml").
30 31 32 |
# File 'lib/uniword/ooxml/part_definition.rb', line 30 def path @path end |
#path_pattern ⇒ String? (readonly)
Returns path template for instance-numbered parts.
33 34 35 |
# File 'lib/uniword/ooxml/part_definition.rb', line 33 def path_pattern @path_pattern end |
#rel_type ⇒ String? (readonly)
Returns relationship type URI (nil when the part is not referenced by a relationship).
48 49 50 |
# File 'lib/uniword/ooxml/part_definition.rb', line 48 def rel_type @rel_type end |
#rels_scope ⇒ Symbol? (readonly)
Returns :package or :document — which .rels part
the relationship lives in (nil when rel_type is nil).
62 63 64 |
# File 'lib/uniword/ooxml/part_definition.rb', line 62 def rels_scope @rels_scope end |
#required ⇒ Boolean (readonly)
Returns whether a minimal valid package carries it.
54 55 56 |
# File 'lib/uniword/ooxml/part_definition.rb', line 54 def required @required end |
#standard ⇒ Boolean (readonly)
Returns whether ContentTypes.generate includes it in the comprehensive [Content_Types].xml for new DOCX packages.
66 67 68 |
# File 'lib/uniword/ooxml/part_definition.rb', line 66 def standard @standard end |
#target ⇒ String? (readonly)
Returns relationship Target as written in .rels
(relative to the owning part; defaults to path).
37 38 39 |
# File 'lib/uniword/ooxml/part_definition.rb', line 37 def target @target end |
#target_pattern ⇒ String? (readonly)
Returns Target template for numbered parts.
40 41 42 |
# File 'lib/uniword/ooxml/part_definition.rb', line 40 def target_pattern @target_pattern end |
Instance Method Details
#==(other) ⇒ Object
Two definitions are equal when every field matches.
147 148 149 |
# File 'lib/uniword/ooxml/part_definition.rb', line 147 def ==(other) other.is_a?(PartDefinition) && fields == other.fields end |
#default? ⇒ Boolean
Returns true for [Content_Types].xml Default entries.
94 95 96 |
# File 'lib/uniword/ooxml/part_definition.rb', line 94 def default? kind == :default end |
#override? ⇒ Boolean
Returns true for [Content_Types].xml Override entries.
89 90 91 |
# File 'lib/uniword/ooxml/part_definition.rb', line 89 def override? kind == :override end |
#package_rel? ⇒ Boolean
Returns true when the relationship lives in _rels/.rels.
109 110 111 |
# File 'lib/uniword/ooxml/part_definition.rb', line 109 def package_rel? rels_scope == :package end |
#part_name ⇒ String?
Fixed-path Override part name (leading slash).
142 143 144 |
# File 'lib/uniword/ooxml/part_definition.rb', line 142 def part_name path && "/#{path}" end |
#part_name_for(**vars) ⇒ String?
Resolve the content-type Override part name (leading slash).
126 127 128 129 |
# File 'lib/uniword/ooxml/part_definition.rb', line 126 def part_name_for(**vars) resolved = path_for(**vars) resolved && "/#{resolved}" end |
#path_for(**vars) ⇒ String?
Resolve the package-relative path, interpolating pattern placeholders for instance-numbered parts.
118 119 120 |
# File 'lib/uniword/ooxml/part_definition.rb', line 118 def path_for(**vars) (path_pattern || path, vars) end |
#required? ⇒ Boolean
Returns true when a minimal valid package carries it.
99 100 101 |
# File 'lib/uniword/ooxml/part_definition.rb', line 99 def required? !!required end |
#standard? ⇒ Boolean
Returns true when ContentTypes.generate includes it.
104 105 106 |
# File 'lib/uniword/ooxml/part_definition.rb', line 104 def standard? !!standard end |
#target_for(**vars) ⇒ String?
Resolve the relationship Target attribute.
135 136 137 |
# File 'lib/uniword/ooxml/part_definition.rb', line 135 def target_for(**vars) (target_pattern || target, vars) end |