class AbstractMapper::Rules::Base
Base
class for optimization rules
@abstract
@api private
Attributes
nodes[R]
@!attribute [r] nodes
@return [Array<AbstractMapper::AST::Node>]
Either one or two nodes to be optimized
Public Class Methods
new(*nodes)
click to toggle source
Initializes the rule for a sole node, or a pair of consecutive nodes
@param [Array<AbstractMapper::AST::Node>] nodes
@return [AbstractMapper::Rules::Base]
# File lib/abstract_mapper/rules/base.rb, line 42 def initialize(*nodes) @nodes = nodes IceNine.deep_freeze(self) end
transproc()
click to toggle source
The transformation function that applies the rule to the array of nodes
@return [Transproc::Function]
# File lib/abstract_mapper/rules/base.rb, line 25 def self.transproc Functions[composer, proc { |*nodes| new(*nodes).call }] end
Private Class Methods
composer()
click to toggle source
@private
# File lib/abstract_mapper/rules/base.rb, line 16 def self.composer :identity end
Public Instance Methods
call()
click to toggle source
Returns the result of the rule applied to the initialized [#nodes]
@return [Array<AbstractMapper::AST::Node>]
# File lib/abstract_mapper/rules/base.rb, line 66 def call optimize? ? [optimize].flatten.compact : nodes end
optimize()
click to toggle source
Returns the optimized node(s)
@return [Object]
# File lib/abstract_mapper/rules/base.rb, line 58 def optimize nodes end
optimize?()
click to toggle source
Checks if optimization is needed for the node(s)
@return [Boolean]
# File lib/abstract_mapper/rules/base.rb, line 51 def optimize? end