Class: Ripe::Blocks::MultiBlock Abstract
- Defined in:
- lib/ripe/blocks/multi_block.rb
Overview
This class represents a block composition, that is, a placeholder block that joins multiple blocks together.
This class only exists to provide a superclass for ParallelBlock and SerialBlock.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Block
Instance Method Summary collapse
-
#initialize(id, *blocks) ⇒ MultiBlock
constructor
Create a new, empty MultiBlock.
-
#prune(protect, depend) ⇒ Block?
Prune the subtree starting at the current block.
-
#targets_exist? ⇒ Boolean
Test whether all targets for the current block exist.
-
#topology ⇒ Array<Symbol, Array>
Return the topology of the subtree starting at the current block in a nested list format.
Methods inherited from Block
Constructor Details
#initialize(id, *blocks) ⇒ MultiBlock
Create a new, empty Ripe::Blocks::MultiBlock.
26 27 28 29 |
# File 'lib/ripe/blocks/multi_block.rb', line 26 def initialize(id, *blocks) # Ignore nil objects super(id, blocks.compact, {}) end |
Instance Method Details
#prune(protect, depend) ⇒ Block?
Prune the subtree starting at the current block.
Unless the block is protected, attempt to prune all children blocks. If all blocks are pruned, return nothing. If a single block remains, return that block. If more than one block remains, return the current Ripe::Blocks::MultiBlock.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ripe/blocks/multi_block.rb', line 39 def prune(protect, depend) if !protect @blocks = @blocks.map { |block| block.prune(protect, depend) }.compact case @blocks.length when 0; nil when 1; @blocks.first else; self end else self end end |
#targets_exist? ⇒ Boolean
Test whether all targets for the current block exist.
A Ripe::Blocks::MultiBlock‘s targets exist if the targets of all its # children exist.
58 59 60 |
# File 'lib/ripe/blocks/multi_block.rb', line 58 def targets_exist? @blocks.map(&:targets_exist?).inject(:&) end |
#topology ⇒ Array<Symbol, Array>
Return the topology of the subtree starting at the current block in a nested list format. The first element of any nested list is the identifier of the corresponding block in the subtree, and the subsequent elements are each a subtree corresponding to the children blocks of the current subtree.
65 66 67 |
# File 'lib/ripe/blocks/multi_block.rb', line 65 def topology [@id] + @blocks.map(&:topology) end |