Class: Patch::Node::Map
- Inherits:
-
Object
- Object
- Patch::Node::Map
- Defined in:
- lib/patch/node/map.rb
Overview
A map of connections between nodes for a given patch
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#disable(patch) ⇒ Boolean
Disable the map for the given patch context.
-
#enable(patch) ⇒ Boolean
Enable this map for the given nodes.
-
#initialize(from, to) ⇒ Map
constructor
A new instance of Map.
-
#nodes ⇒ NodeContainer
The nodes for this map, collected.
Constructor Details
#initialize(from, to) ⇒ Map
Returns a new instance of Map.
12 13 14 15 |
# File 'lib/patch/node/map.rb', line 12 def initialize(from, to) @from = to_node_container(from) @to = to_node_container(to) end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
8 9 10 |
# File 'lib/patch/node/map.rb', line 8 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
8 9 10 |
# File 'lib/patch/node/map.rb', line 8 def to @to end |
Instance Method Details
#disable(patch) ⇒ Boolean
Disable the map for the given patch context
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/patch/node/map.rb', line 19 def disable(patch) result = @to.map do |to_node| disabled = @from.map do |from_node| from_node.disable(patch) true end disabled.any? end result.any? end |
#enable(patch) ⇒ Boolean
Enable this map for the given nodes
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/patch/node/map.rb', line 33 def enable(patch) result = @to.map do |to_node| enabled = @from.map do |from_node| from_node.listen(patch) do || to_node.puts(patch, ) end true end enabled.any? end result.flatten.any? end |
#nodes ⇒ NodeContainer
The nodes for this map, collected
48 49 50 |
# File 'lib/patch/node/map.rb', line 48 def nodes @from | @to end |