Class: AbstractMapper::Node
- Inherits:
-
Object
- Object
- AbstractMapper::Node
- Includes:
- Attributes, Comparable
- Defined in:
- lib/abstract_mapper/node.rb
Overview
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.
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]).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Proc
readonly
The block given to initializer.
Attributes included from Attributes
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compares the node to another one by type and attributes.
-
#initialize(_ = {}, &block) ⇒ Node
constructor
A new instance of Node.
-
#inspect ⇒ String
Returns a human-readable string representating the node.
-
#to_s ⇒ String
Converts the node into string with its name and attributes.
-
#transproc ⇒ Transproc::Function
abstract
The transformation function for the branch.
Methods included from Attributes
Constructor Details
#initialize(_ = {}, &block) ⇒ Node
Returns a new instance of Node.
30 31 32 33 34 |
# File 'lib/abstract_mapper/node.rb', line 30 def initialize(_ = {}, &block) super @block = block IceNine.deep_freeze(self) end |
Instance Attribute Details
#block ⇒ Proc (readonly)
Returns The block given to initializer.
27 28 29 |
# File 'lib/abstract_mapper/node.rb', line 27 def block @block end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compares the node to another one by type and attributes
69 70 71 |
# File 'lib/abstract_mapper/node.rb', line 69 def ==(other) other.instance_of?(self.class) && attributes.eql?(other.attributes) end |
#inspect ⇒ String
Returns a human-readable string representating the node
51 52 53 |
# File 'lib/abstract_mapper/node.rb', line 51 def inspect "<#{self}>" end |
#to_s ⇒ String
Converts the node into string with its name and attributes
59 60 61 |
# File 'lib/abstract_mapper/node.rb', line 59 def to_s "#{__name__}#{__attributes__}" end |
#transproc ⇒ Transproc::Function
The transformation function for the branch
43 44 45 |
# File 'lib/abstract_mapper/node.rb', line 43 def transproc Functions[:identity] end |