class AbstractMapper::AST::Node

An immutable node of the abstract syntax tree (AST), that describes either some “end-up” transformation, or a level of nested input data.

Every node is expected to accept attributes and (possibly) block, and implement `#transproc` that implements the `#call` method to transform input data to the output.

AST::Nodes describe only the structure of AST, they know neither how to build the tree with DSL (see [AbstractMapper::Builder]), nor how to optimize it later (see [AbstractMapper::Optimizer]).

@api public

Attributes

block[R]

@!attribute [r] block

@return [Proc] The block given to initializer

Public Class Methods

new(_ = {}, &block) click to toggle source

@private

Calls superclass method
# File lib/abstract_mapper/ast/node.rb, line 32
def initialize(_ = {}, &block)
  super
  @block = block
  IceNine.deep_freeze(self)
end

Public Instance Methods

==(other) click to toggle source

Compares the node to another one by type and attributes

@param [Object] other

@return [Boolean]

# File lib/abstract_mapper/ast/node.rb, line 71
def ==(other)
  other.instance_of?(self.class) && attributes.eql?(other.attributes)
end
Also aliased as: eql?
eql?(other)
Alias for: ==
inspect() click to toggle source

Returns a human-readable string representating the node

@return [String]

# File lib/abstract_mapper/ast/node.rb, line 53
def inspect
  "<#{self}>"
end
to_s() click to toggle source

Converts the node into string with its name and attributes

@return [String]

# File lib/abstract_mapper/ast/node.rb, line 61
def to_s
  "#{__name__}#{__attributes__}"
end
transproc() click to toggle source

@!method transproc The transformation function for the branch

@return [Transproc::Function]

@abstract

# File lib/abstract_mapper/ast/node.rb, line 45
def transproc
  Functions[:identity]
end

Private Instance Methods

__attributes__() click to toggle source
# File lib/abstract_mapper/ast/node.rb, line 82
def __attributes__
  return if attributes.empty?
  "(#{attributes.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")})"
end
__name__() click to toggle source
# File lib/abstract_mapper/ast/node.rb, line 78
def __name__
  self.class.name.split("::").last
end