Class: Uniword::Transformation::ImageTransformationRule
- Inherits:
-
TransformationRule
- Object
- TransformationRule
- Uniword::Transformation::ImageTransformationRule
- Defined in:
- lib/uniword/transformation/image_transformation_rule.rb
Overview
Transformation rule for Image elements.
Responsibility: Transform Image objects between DOCX and MHTML formats. Single Responsibility - handles only Image transformations.
Transforms image properties including positioning, dimensions, and metadata.
Instance Attribute Summary
Attributes inherited from TransformationRule
#source_format, #target_format
Instance Method Summary collapse
-
#matches?(element_type:, source_format:, target_format:) ⇒ Boolean
Check if this rule matches the transformation request.
-
#transform(source_image) ⇒ Image
Transform an image from source format to target format.
Methods inherited from TransformationRule
Constructor Details
This class inherits a constructor from Uniword::Transformation::TransformationRule
Instance Method Details
#matches?(element_type:, source_format:, target_format:) ⇒ Boolean
Check if this rule matches the transformation request
22 23 24 25 26 |
# File 'lib/uniword/transformation/image_transformation_rule.rb', line 22 def matches?(element_type:, source_format:, target_format:) element_type == Image && source_format == @source_format && target_format == @target_format end |
#transform(source_image) ⇒ Image
Transform an image from source format to target format
Creates new Image with adapted properties.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/uniword/transformation/image_transformation_rule.rb', line 35 def transform(source_image) validate_element_type(source_image, Image) # Create new image with core properties target_image = Image.new( relationship_id: source_image.relationship_id, width: source_image.width, height: source_image.height, filename: source_image.filename, alt_text: source_image.alt_text, title: source_image.title, ) # Transform positioning properties transform_positioning(source_image, target_image) target_image end |