Class: Diaspora::Cluster::Creator::EdgeCollectionFactory
- Inherits:
-
Object
- Object
- Diaspora::Cluster::Creator::EdgeCollectionFactory
- Extended by:
- DependencyInjector
- Defined in:
- lib/diaspora-cluster-creator/edge_collection_factory.rb
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
Instance Method Summary collapse
- #build_from(nodes) ⇒ Object
-
#initialize(cluster) ⇒ EdgeCollectionFactory
constructor
A new instance of EdgeCollectionFactory.
Constructor Details
#initialize(cluster) ⇒ EdgeCollectionFactory
Returns a new instance of EdgeCollectionFactory.
8 9 10 |
# File 'lib/diaspora-cluster-creator/edge_collection_factory.rb', line 8 def initialize(cluster) @cluster = cluster end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
7 8 9 |
# File 'lib/diaspora-cluster-creator/edge_collection_factory.rb', line 7 def cluster @cluster end |
Instance Method Details
#build_from(nodes) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/diaspora-cluster-creator/edge_collection_factory.rb', line 12 def build_from(nodes) return @edges if @edges nodes.each_with_index do |node, i| result = dice.roll if result < 0 connect(node, nodes[i+1]) elsif result == 0 connect(node, nodes[i+1], nodes[i+2]) elsif result > 0 connect(node, nodes[i+1], nodes[i+2], nodes[i+3]) end end @edges end |