Class: YamlDag
Instance Method Summary collapse
- #ancestors(task) ⇒ Object
- #build ⇒ Object
-
#initialize(filepath) ⇒ YamlDag
constructor
A new instance of YamlDag.
- #root(task) ⇒ Object
- #vertices ⇒ Object
- #visualize ⇒ Object
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 |
#build ⇒ Object
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 |
#vertices ⇒ Object
35 36 37 |
# File 'lib/yamldag.rb', line 35 def vertices puts "Vertices #{@dag.vertices}" end |
#visualize ⇒ Object
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 |