Class: AbstractMapper::PairRule Abstract

Inherits:
Rule
  • Object
show all
Defined in:
lib/abstract_mapper/pair_rule.rb

Overview

This class is abstract.

The base class for rules to be applied to pairs of nodes.

The subclass should implement two instance methods:

  • ‘#optimize?` to check if the optimization should be applied to the nodes

  • ‘#optimize` that should return the merged node

Examples:

class MergeConsecutiveLists < AbstractMapper::PairRule
  def optimize?
    left.is_a?(List) & right.is_a?(List)
  end

  def optimize
    List.new { left.entries + right.entries }
  end
end

Instance Attribute Summary collapse

Attributes inherited from Rule

#nodes

Class Method Summary collapse

Methods inherited from Rule

call, optimize, optimize?, transproc

Instance Attribute Details

#leftAbstractMapper::Node (readonly)

Returns The left node in the pair to be optimized.

Returns:



39
40
41
# File 'lib/abstract_mapper/pair_rule.rb', line 39

def left
  @left
end

#nodeAbstractMapper::Node (readonly)

Returns The right node in the pair to be optimized.

Returns:



39
# File 'lib/abstract_mapper/pair_rule.rb', line 39

attr_reader :left

#rightAbstractMapper::Node (readonly)

Returns The right node in the pair to be optimized.

Returns:



45
46
47
# File 'lib/abstract_mapper/pair_rule.rb', line 45

def right
  @right
end

Class Method Details

.initialize(left, right) ⇒ Object



56
57
58
59
60
# File 'lib/abstract_mapper/pair_rule.rb', line 56

def initialize(left, right)
  @left  = left
  @right = right
  super
end

.new(node) ⇒ AbstractMapper::Rule

Creates a rule applied to the sole node

Parameters:

Returns:



# File 'lib/abstract_mapper/pair_rule.rb', line 47