Class: Uniword::Docx::ImagePart
- Defined in:
- lib/uniword/docx/image_part.rb
Overview
An image part (word/media/*) held by the package: binary image data plus the packaging metadata needed to emit it (relationship target, relationship id, content type).
The image content type is per-file (resolved from the file extension), so it is always carried explicitly — the registry's :image definition contributes only the relationship type.
Replaces the raw { data:, target:, content_type:, path: } hash
entries formerly stored in DocumentRoot#image_parts. Hash-style
read access (+part+, part[:target], part[:content_type],
part[:path]) is kept for backward compatibility.
Constant Summary
Constants inherited from Part
Instance Attribute Summary collapse
-
#source_path ⇒ String?
Path of the source file the image was read from (builder-added images only; nil for loaded parts).
Attributes inherited from Part
#content, #content_type, #definition, #r_id, #rel_type, #target
Class Method Summary collapse
-
.from_hash(hash) ⇒ ImagePart
Wrap a legacy raw-hash entry ({ data:, target:, content_type:, path: }) into an ImagePart.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Hash-style read compatibility (+:data+ and the legacy
:pathsource path in addition to the Part keys). -
#data ⇒ String?
Binary image data (alias for content).
-
#data=(value) ⇒ void
Set the binary image data (alias for content=).
-
#initialize(r_id: nil, target: nil, data: nil, content_type: nil, source_path: nil, **rest) ⇒ ImagePart
constructor
rubocop:disable Metrics/ParameterLists.
Methods inherited from Part
Constructor Details
#initialize(r_id: nil, target: nil, data: nil, content_type: nil, source_path: nil, **rest) ⇒ ImagePart
rubocop:disable Metrics/ParameterLists
36 37 38 39 40 41 42 43 44 |
# File 'lib/uniword/docx/image_part.rb', line 36 def initialize(r_id: nil, target: nil, data: nil, content_type: nil, source_path: nil, **rest) super( definition: Ooxml::PartRegistry.find_by_key(:image), r_id: r_id, target: target, content: data, content_type: content_type, **rest ) @source_path = source_path end |
Instance Attribute Details
#source_path ⇒ String?
Returns path of the source file the image was read from (builder-added images only; nil for loaded parts).
28 29 30 |
# File 'lib/uniword/docx/image_part.rb', line 28 def source_path @source_path end |
Class Method Details
.from_hash(hash) ⇒ ImagePart
Wrap a legacy raw-hash entry ({ data:, target:, content_type:, path: }) into an ImagePart.
52 53 54 55 |
# File 'lib/uniword/docx/image_part.rb', line 52 def self.from_hash(hash) new(target: hash[:target], data: hash[:data], content_type: hash[:content_type], source_path: hash[:path]) end |
Instance Method Details
#[](key) ⇒ Object
Hash-style read compatibility (+:data+ and the legacy :path
source path in addition to the Part keys).
74 75 76 77 78 79 80 |
# File 'lib/uniword/docx/image_part.rb', line 74 def [](key) case key.to_sym when :data then content when :path then source_path else super end end |
#data ⇒ String?
Binary image data (alias for content).
60 61 62 |
# File 'lib/uniword/docx/image_part.rb', line 60 def data content end |
#data=(value) ⇒ void
This method returns an undefined value.
Set the binary image data (alias for content=).
68 69 70 |
# File 'lib/uniword/docx/image_part.rb', line 68 def data=(value) self.content = value end |