Class: Uniword::Transformation::TableTransformationRule

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

Overview

Transformation rule for Table elements.

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

Transforms table structure including rows, cells, and all properties.

Examples:

Transform DOCX table to MHTML

rule = TableTransformationRule.new(source_format: :docx, target_format: :mhtml)
mhtml_table = rule.transform(docx_table)

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



22
23
24
25
26
# File 'lib/uniword/transformation/table_transformation_rule.rb', line 22

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

#transform(source_table) ⇒ Table

Transform a table from source format to target format

Creates new Table with all rows and cells transformed.

Parameters:

  • source_table (Table)

    Source table

Returns:

  • (Table)

    Transformed table

Raises:

  • (ArgumentError)

    if source_table is not a Table



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

def transform(source_table)
  validate_element_type(source_table, Table)

  target_table = Table.new

  # Transform table-level properties
  transform_properties(source_table, target_table)

  # Transform each row
  source_table.rows.each do |source_row|
    target_row = transform_row(source_row)
    target_table.rows << target_row
  end

  target_table
end