Class: Rukawa::Dag
Defined Under Namespace
Classes: Edge
Instance Attribute Summary collapse
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(job_net, dependencies) ⇒ Dag
constructor
A new instance of Dag.
- #leaves ⇒ Object
- #roots ⇒ Object
Constructor Details
#initialize(job_net, dependencies) ⇒ Dag
Returns a new instance of Dag.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rukawa/dag.rb', line 9 def initialize(job_net, dependencies) deps = tsortable_hash(dependencies).tsort @jobs = Set.new @edges = Set.new deps.each do |job_class| job = job_class.new(job_net) @jobs << job dependencies[job_class].each do |depend_job_class| depend_job = @jobs.find { |j| j.instance_of?(depend_job_class) } depend_job.nodes_as_from.each do |from| job.nodes_as_to.each do |to| edge = Edge.new(from, to) @edges << edge from.out_goings << edge to.in_comings << edge end end end end end |
Instance Attribute Details
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
7 8 9 |
# File 'lib/rukawa/dag.rb', line 7 def edges @edges end |
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
7 8 9 |
# File 'lib/rukawa/dag.rb', line 7 def jobs @jobs end |
Instance Method Details
#each ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/rukawa/dag.rb', line 33 def each if block_given? @jobs.each { |j| yield j } else @jobs.each end end |
#leaves ⇒ Object
45 46 47 |
# File 'lib/rukawa/dag.rb', line 45 def leaves select(&:leaf?) end |
#roots ⇒ Object
41 42 43 |
# File 'lib/rukawa/dag.rb', line 41 def roots select(&:root?) end |