Class: AbstractMapper::AST::Branch
- Includes:
- Enumerable
- Defined in:
- lib/abstract_mapper/ast/branch.rb
Overview
A special type of the composed node, that describes transformation, applied to some level of nested input.
Unlike the simple node, describing a transformation of data, the branch carries a collection of subnodes along with methods to [#update] itself with the same attributes and different subnodes.
Tne branch only stores subnodes and composes transformations. Its has no access to DSL and knows neither how to build a tree (see [AbstractMapper::Builder]), nor how to optimize it later (see [AbstractMapper::Optimizer]).
Instance Attribute Summary
Attributes inherited from Node
Class Method Summary collapse
-
.<<(other) ⇒ AbstractMapper::Branch
Returns a new branch with the other node added to its subnodes.
-
.each ⇒ Enumerator
Returns the enumerator for subnodes.
-
.eql?(other) ⇒ Boolean
Checks equality of branches by type, attributes and subnodes.
- .initialize(attributes = {}) ⇒ Object
-
.new(*attributes, &block) ⇒ Branch::AST::Node
Creates a new branch.
-
.to_s ⇒ String
Adds subnodes to the default description of the branch.
-
.transproc ⇒ Transproc::Function
abstract
The composition of transformations from all subnodes of the branch.
-
.update { ... } ⇒ AbstractMapper::Branch
Returns a new branch of the same type, with the same attributes, but with a different collection of subnodes, transmitted by the block.
Methods inherited from Node
#==, #initialize, #inspect, #to_s, #transproc
Constructor Details
This class inherits a constructor from AbstractMapper::AST::Node
Class Method Details
.<<(other) ⇒ AbstractMapper::Branch
Returns a new branch with the other node added to its subnodes
74 75 76 |
# File 'lib/abstract_mapper/ast/branch.rb', line 74 def <<(other) update { entries << other } end |
.each ⇒ Enumerator
Returns the enumerator for subnodes
64 65 66 |
# File 'lib/abstract_mapper/ast/branch.rb', line 64 def each(&block) @subnodes.each(&block) end |
.eql?(other) ⇒ Boolean
Checks equality of branches by type, attributes and subnodes
105 106 107 |
# File 'lib/abstract_mapper/ast/branch.rb', line 105 def eql?(other) super && entries.eql?(other.entries) end |
.initialize(attributes = {}) ⇒ Object
37 38 39 40 |
# File 'lib/abstract_mapper/ast/branch.rb', line 37 def initialize(attributes = {}) @subnodes = block_given? ? yield : [] super(attributes, &nil) end |
.new(*attributes, &block) ⇒ Branch::AST::Node
Creates a new branch
|
# File 'lib/abstract_mapper/ast/branch.rb', line 25
|
.to_s ⇒ String
Adds subnodes to the default description of the branch
95 96 97 |
# File 'lib/abstract_mapper/ast/branch.rb', line 95 def to_s "#{super} [#{map(&:inspect).join(", ")}]" end |
.transproc ⇒ Transproc::Function
The composition of transformations from all subnodes of the branch
To be reloaded by the subclasses to apply the composition to a corresponding level of nested data.
87 88 89 |
# File 'lib/abstract_mapper/ast/branch.rb', line 87 def transproc map(&:transproc).inject(:>>) end |
.update { ... } ⇒ AbstractMapper::Branch
Returns a new branch of the same type, with the same attributes, but with a different collection of subnodes, transmitted by the block.
55 56 57 |
# File 'lib/abstract_mapper/ast/branch.rb', line 55 def update self.class.new(attributes) { yield } end |