Class: Uniword::Transformation::TransformationRuleRegistry
- Inherits:
-
Object
- Object
- Uniword::Transformation::TransformationRuleRegistry
- Defined in:
- lib/uniword/transformation/transformation_rule_registry.rb
Overview
Registry for transformation rules.
Responsibility: Manage registration and lookup of transformation rules. Single Responsibility - only handles rule registration and retrieval.
Follows Open/Closed Principle - new rules can be registered without modifying this class.
Follows MECE Principle - each rule is mutually exclusive (handles specific element types and format combinations), and collectively exhaustive (fallback to NullTransformationRule ensures coverage).
Instance Method Summary collapse
-
#clear ⇒ self
Clear all registered rules.
-
#count ⇒ Integer
Get count of registered rules.
-
#empty? ⇒ Boolean
Check if any rules are registered.
-
#find_rule(element_type:, source_format:, target_format:) ⇒ TransformationRule
Find a rule matching the given criteria.
-
#initialize ⇒ TransformationRuleRegistry
constructor
Initialize empty registry.
-
#register(rule) ⇒ self
Register a transformation rule.
-
#register_all(rules) ⇒ self
Register multiple rules at once.
-
#rules ⇒ Array<TransformationRule>
Get all registered rules.
Constructor Details
#initialize ⇒ TransformationRuleRegistry
Initialize empty registry
31 32 33 34 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 31 def initialize @rules = [] @null_rule = NullTransformationRule.new end |
Instance Method Details
#clear ⇒ self
Clear all registered rules
Useful for testing or reconfiguration
102 103 104 105 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 102 def clear @rules.clear self end |
#count ⇒ Integer
Get count of registered rules
86 87 88 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 86 def count @rules.count end |
#empty? ⇒ Boolean
Check if any rules are registered
93 94 95 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 93 def empty? @rules.empty? end |
#find_rule(element_type:, source_format:, target_format:) ⇒ TransformationRule
Find a rule matching the given criteria
Returns the first matching rule, or NullTransformationRule if none match. NullTransformationRule returns element unchanged (deep copy).
66 67 68 69 70 71 72 73 74 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 66 def find_rule(element_type:, source_format:, target_format:) @rules.find do |rule| rule.matches?( element_type: element_type, source_format: source_format, target_format: target_format, ) end || @null_rule end |
#register(rule) ⇒ self
Register a transformation rule
44 45 46 47 48 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 44 def register(rule) validate_rule(rule) @rules << rule self end |
#register_all(rules) ⇒ self
Register multiple rules at once
114 115 116 117 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 114 def register_all(rules) rules.each { |rule| register(rule) } self end |
#rules ⇒ Array<TransformationRule>
Get all registered rules
79 80 81 |
# File 'lib/uniword/transformation/transformation_rule_registry.rb', line 79 def rules @rules.dup end |