Class: OpenBEL::Helpers::DependencyGraph
- Inherits:
-
Object
- Object
- OpenBEL::Helpers::DependencyGraph
- Includes:
- TSort
- Defined in:
- lib/openbel/api/helpers/dependency_graph.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_dependency(first, *dependency_requirements) ⇒ Object
- #delete(key) ⇒ Object
- #each_key(&block) ⇒ Object
-
#initialize ⇒ DependencyGraph
constructor
A new instance of DependencyGraph.
- #tsort_each_child(key, &block) ⇒ Object
- #tsort_each_node(&block) ⇒ Object
Constructor Details
#initialize ⇒ DependencyGraph
Returns a new instance of DependencyGraph.
9 10 11 |
# File 'lib/openbel/api/helpers/dependency_graph.rb', line 9 def initialize @hash = Hash.new { |hash, key| hash[key] = [] } end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 |
# File 'lib/openbel/api/helpers/dependency_graph.rb', line 13 def [](key) @hash[key] end |
#add_dependency(first, *dependency_requirements) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/openbel/api/helpers/dependency_graph.rb', line 17 def add_dependency(first, *dependency_requirements) @hash[first] ||= [] (dependency_requirements || []).flatten.each do |dep| _add_dependency(first, dep) end @hash[first] end |
#delete(key) ⇒ Object
25 26 27 |
# File 'lib/openbel/api/helpers/dependency_graph.rb', line 25 def delete(key) @hash.delete(key) end |
#each_key(&block) ⇒ Object
29 30 31 |
# File 'lib/openbel/api/helpers/dependency_graph.rb', line 29 def each_key(&block) @hash.each_key(&block) end |
#tsort_each_child(key, &block) ⇒ Object
33 34 35 |
# File 'lib/openbel/api/helpers/dependency_graph.rb', line 33 def tsort_each_child(key, &block) @hash[key].each(&block) end |
#tsort_each_node(&block) ⇒ Object
37 38 39 |
# File 'lib/openbel/api/helpers/dependency_graph.rb', line 37 def tsort_each_node(&block) @hash.each_key(&block) end |