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
@!attribute [r] block
@return [Proc] The block given to initializer
Public Class Methods
@private
# File lib/abstract_mapper/ast/node.rb, line 32 def initialize(_ = {}, &block) super @block = block IceNine.deep_freeze(self) end
Public Instance Methods
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
Returns a human-readable string representating the node
@return [String]
# File lib/abstract_mapper/ast/node.rb, line 53 def inspect "<#{self}>" end
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
@!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
# File lib/abstract_mapper/ast/node.rb, line 82 def __attributes__ return if attributes.empty? "(#{attributes.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")})" end
# File lib/abstract_mapper/ast/node.rb, line 78 def __name__ self.class.name.split("::").last end