Class: YamlDag

Inherits:
Object
  • Object
show all
Includes:
Plexus
Defined in:
lib/yamldag.rb

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ YamlDag

Returns a new instance of YamlDag.



7
8
9
10
# File 'lib/yamldag.rb', line 7

def initialize(filepath) 
  @dag = DirectedGraph.new # alias of Digraph
  @filepath = filepath
end

Instance Method Details

#ancestors(task) ⇒ Object



39
40
41
# File 'lib/yamldag.rb', line 39

def ancestors(task)
  dag.ancestors(task)
end

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yamldag.rb', line 12

def build
  add_vertices_and_edges
  # is cycle graph ?
  if @dag.cyclic?
    # puts "strong_components  ==> #{@dag.strong_components}"
    @nodes = @dag.strong_components.select{|a| a.length > 1}
    @nodes.each do | ns |
      puts "--------------cyclic------------------"
      puts "#{ns.reverse.join('-->')}-->#{ns.reverse.first}"
    end
  end
  if @dag.acyclic? 
    # puts "--------------topsort------------------"
    # puts "#{@dag.topsort}"
    puts "--------------dfs------------------"
    puts "#{@dag.dfs}"
    puts "--------------bfs------------------"
    puts "#{@dag.bfs}"
  end
  puts "--------------visualize------------------"
  visualize
end

#root(task) ⇒ Object



43
44
45
# File 'lib/yamldag.rb', line 43

def root(task)
  ancestors(task).last
end

#verticesObject



35
36
37
# File 'lib/yamldag.rb', line 35

def vertices 
  puts "Vertices #{@dag.vertices}"
end

#visualizeObject



47
48
49
50
51
# File 'lib/yamldag.rb', line 47

def visualize
  # just a graph.dot
  # filename = dag.dotty and puts "Created  xx #{filename}"
  filename = dag.write_to_graphic_file('svg') and puts "Created #{filename}"
end