Class: AbstractMapper::Branch
- Includes:
- Enumerable
- Defined in:
- lib/abstract_mapper/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 [#rebuild] 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.
- .initialize(*attributes) ⇒ Object
-
.new(*attributes, &block) ⇒ Branch::Node
Creates a new branch.
-
.rebuild(&block) { ... } ⇒ 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.
-
.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.
Methods inherited from Node
#initialize, #inspect, #to_s, #transproc
Constructor Details
This class inherits a constructor from AbstractMapper::Node
Class Method Details
.<<(other) ⇒ AbstractMapper::Branch
Returns a new branch with the other node added to its subnodes
75 76 77 |
# File 'lib/abstract_mapper/branch.rb', line 75 def <<(other) rebuild { entries << other } end |
.each ⇒ Enumerator
Returns the enumerator for subnodes
65 66 67 |
# File 'lib/abstract_mapper/branch.rb', line 65 def each(&block) @subnodes.each(&block) end |
.initialize(*attributes) ⇒ Object
35 36 37 38 |
# File 'lib/abstract_mapper/branch.rb', line 35 def initialize(*attributes) @subnodes = block_given? ? yield : [] super(*attributes, &nil) end |
.new(*attributes, &block) ⇒ Branch::Node
Creates a new branch
|
|
# File 'lib/abstract_mapper/branch.rb', line 23
|
.rebuild(&block) { ... } ⇒ 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.
56 57 58 |
# File 'lib/abstract_mapper/branch.rb', line 56 def rebuild(&block) self.class.new(*attributes, &block) end |
.to_s ⇒ String
Adds subnodes to the default description of the branch
96 97 98 |
# File 'lib/abstract_mapper/branch.rb', line 96 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.
88 89 90 |
# File 'lib/abstract_mapper/branch.rb', line 88 def transproc map(&:transproc).inject(:>>) end |