Class: Uniword::Transformation::ParagraphTransformationRule

Inherits:
TransformationRule show all
Defined in:
lib/uniword/transformation/paragraph_transformation_rule.rb

Overview

Transformation rule for Paragraph elements.

Responsibility: Transform Paragraph objects between DOCX and MHTML formats. Single Responsibility - handles only Paragraph transformations.

Transformations handle format-specific property conversions:

  • DOCX → MHTML: Convert OOXML properties to CSS-compatible properties

  • MHTML → DOCX: Convert CSS properties to OOXML properties

Examples:

Transform DOCX paragraph to MHTML

rule = ParagraphTransformationRule.new(source_format: :docx, target_format: :mhtml)
mhtml_para = rule.transform(docx_para)

Instance Attribute Summary

Attributes inherited from TransformationRule

#source_format, #target_format

Instance Method Summary collapse

Methods inherited from TransformationRule

#initialize

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

Parameters:

  • element_type (Class)

    The element class

  • source_format (Symbol)

    Source format

  • target_format (Symbol)

    Target format

Returns:

  • (Boolean)

    true if matches



24
25
26
27
28
# File 'lib/uniword/transformation/paragraph_transformation_rule.rb', line 24

def matches?(element_type:, source_format:, target_format:)
  element_type == Paragraph &&
    source_format == @source_format &&
    target_format == @target_format
end

#transform(source_para) ⇒ Paragraph

Transform a paragraph from source format to target format

Creates new Paragraph with adapted properties and transformed runs.

Parameters:

  • source_para (Paragraph)

    Source paragraph

Returns:

  • (Paragraph)

    Transformed paragraph

Raises:

  • (ArgumentError)

    if source_para is not a Paragraph



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/uniword/transformation/paragraph_transformation_rule.rb', line 37

def transform(source_para)
  validate_element_type(source_para, Paragraph)

  target_para = Paragraph.new

  # Transform properties based on format direction
  transform_properties(source_para, target_para)

  # Transform runs (delegate to RunTransformationRule)
  transform_runs(source_para, target_para)

  target_para
end