Class: Uniword::Transformation::TransformationRule
- Inherits:
-
Object
- Object
- Uniword::Transformation::TransformationRule
- Defined in:
- lib/uniword/transformation/transformation_rule.rb
Overview
Base class for transformation rules.
Responsibility: Define the interface for element transformation rules. Each rule transforms one element type from source format to target format.
Follows Single Responsibility Principle - one rule handles one transformation pattern. Follows Open/Closed Principle - new rules can be added without modifying this class.
Direct Known Subclasses
HyperlinkTransformationRule, ImageTransformationRule, NullTransformationRule, ParagraphTransformationRule, RunTransformationRule, TableTransformationRule
Instance Attribute Summary collapse
-
#source_format ⇒ Object
readonly
Returns the value of attribute source_format.
-
#target_format ⇒ Object
readonly
Returns the value of attribute target_format.
Instance Method Summary collapse
-
#initialize(source_format:, target_format:) ⇒ TransformationRule
constructor
Initialize transformation rule.
-
#matches?(element_type:, source_format:, target_format:) ⇒ Boolean
Check if this rule matches the transformation request.
-
#transform(element) ⇒ Element+
Transform an element from source format to target format.
Constructor Details
#initialize(source_format:, target_format:) ⇒ TransformationRule
Initialize transformation rule
35 36 37 38 |
# File 'lib/uniword/transformation/transformation_rule.rb', line 35 def initialize(source_format:, target_format:) @source_format = source_format @target_format = target_format end |
Instance Attribute Details
#source_format ⇒ Object (readonly)
Returns the value of attribute source_format.
29 30 31 |
# File 'lib/uniword/transformation/transformation_rule.rb', line 29 def source_format @source_format end |
#target_format ⇒ Object (readonly)
Returns the value of attribute target_format.
29 30 31 |
# File 'lib/uniword/transformation/transformation_rule.rb', line 29 def target_format @target_format end |
Instance Method Details
#matches?(element_type:, source_format:, target_format:) ⇒ Boolean
Check if this rule matches the transformation request
46 47 48 |
# File 'lib/uniword/transformation/transformation_rule.rb', line 46 def matches?(element_type:, source_format:, target_format:) raise NotImplementedError, "#{self.class} must implement #matches?" end |
#transform(element) ⇒ Element+
Transform an element from source format to target format
54 55 56 |
# File 'lib/uniword/transformation/transformation_rule.rb', line 54 def transform(element) raise NotImplementedError, "#{self.class} must implement #transform" end |