Class: NRSER::Graph::TSorter

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/nrser/graph/tsorter.rb

Overview

Topologically sorts an Enumerable by a user-provided ‘child_node` block.

Instance Method Summary collapse

Constructor Details

#initialize(entries, &each_child) ⇒ TSorter

Returns a new instance of TSorter.



29
30
31
32
# File 'lib/nrser/graph/tsorter.rb', line 29

def initialize entries, &each_child
  @entries = entries
  @each_child = each_child
end

Instance Method Details

#tsort_each_child(node, &block) ⇒ Object



38
39
40
# File 'lib/nrser/graph/tsorter.rb', line 38

def tsort_each_child node, &block
  @each_child.call node, &block
end

#tsort_each_node(&block) ⇒ Object



34
35
36
# File 'lib/nrser/graph/tsorter.rb', line 34

def tsort_each_node &block
  @entries.each &block
end