Class: AbstractMapper::SoleRule Abstract

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

Overview

This class is abstract.

The abstract class that describes the rule to be applied to sole nodes.

The subclass should implement two instance methods:

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

  • ‘#optimize` that should return the optimized node

Examples:

class RemoveEmptyList < AbstractMapper::SoleRule
  def optimize?
    node.is_a?(List) && node.empty?
  end

  def optimize
  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

#nodeAbstractMapper::Node (readonly)

Returns The node to be optimized.

Returns:



38
39
40
# File 'lib/abstract_mapper/sole_rule.rb', line 38

def node
  @node
end

Class Method Details

.initialize(node) ⇒ Object



49
50
51
52
# File 'lib/abstract_mapper/sole_rule.rb', line 49

def initialize(node)
  @node = node
  super
end

.new(node) ⇒ AbstractMapper::Rule

Creates a rule applied to the sole node

Parameters:

Returns:



# File 'lib/abstract_mapper/sole_rule.rb', line 40