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, transproc

Instance Attribute Details

#nodeAbstractMapper::Node (readonly)

Returns The node to be optimized.

Returns:



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

def node
  @node
end

Class Method Details

.composerSymbol

Returns the name of transproc used to compose rules

Returns:

  • (Symbol)


32
33
34
# File 'lib/abstract_mapper/sole_rule.rb', line 32

def self.composer
  :filter
end

.initialize(node) ⇒ Object



51
52
53
54
# File 'lib/abstract_mapper/sole_rule.rb', line 51

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 42