Class: Rukawa::Dag

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rukawa/dag.rb

Defined Under Namespace

Classes: Edge

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#edgesObject (readonly)

Returns the value of attribute edges.



7
8
9
# File 'lib/rukawa/dag.rb', line 7

def edges
  @edges
end

#jobsObject (readonly)

Returns the value of attribute jobs.



7
8
9
# File 'lib/rukawa/dag.rb', line 7

def jobs
  @jobs
end

Instance Method Details

#eachObject



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

#leavesObject



45
46
47
# File 'lib/rukawa/dag.rb', line 45

def leaves
  select(&:leaf?)
end

#rootsObject



41
42
43
# File 'lib/rukawa/dag.rb', line 41

def roots
  select(&:root?)
end