Class: DependencyTree
- Inherits:
-
Object
- Object
- DependencyTree
- Defined in:
- lib/dependency_tree.rb
Instance Method Summary collapse
-
#initialize(dependency_map) ⇒ DependencyTree
constructor
A new instance of DependencyTree.
- #next_node(current) ⇒ Object
- #previous_node(current) ⇒ Object
- #root ⇒ Object
- #traverse {|current| ... } ⇒ Object
Constructor Details
#initialize(dependency_map) ⇒ DependencyTree
Returns a new instance of DependencyTree.
24 25 26 |
# File 'lib/dependency_tree.rb', line 24 def initialize dependency_map @dependency_map = dependency_map end |
Instance Method Details
#next_node(current) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dependency_tree.rb', line 39 def next_node current return nil if current.to_s.strip.length == 0 return nil if @dependency_map.nil? || @dependency_map.class.to_s != GlobalConstants::HASH || @dependency_map.empty? current = GlobalConstants::ROOT if @dependency_map[GlobalConstants::ROOT][GlobalConstants::PROJECTNAME] == current if @dependency_map[current].has_key? GlobalConstants::NEXT next_node = @dependency_map[current][GlobalConstants::NEXT] next_node = @dependency_map[next_node] next_node = Hashit.new next_node if !next_node.nil? end end |
#previous_node(current) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dependency_tree.rb', line 51 def previous_node current return nil if current.to_s.strip.length == 0 return nil if @dependency_map.nil? || @dependency_map.class.to_s != GlobalConstants::HASH || @dependency_map.empty? if @dependency_map[current].has_key? GlobalConstants::PREVIOUS prev_node = @dependency_map[current][GlobalConstants::PREVIOUS] if @dependency_map[GlobalConstants::ROOT][GlobalConstants::PROJECTNAME] == prev_node prev_node = @dependency_map[GlobalConstants::ROOT] else prev_node = @dependency_map[prev_node] end return nil if prev_node.nil? return Hashit.new prev_node end end |
#root ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dependency_tree.rb', line 28 def root return nil if @dependency_map.nil? || @dependency_map.class.to_s != GlobalConstants::HASH || @dependency_map.empty? if @dependency_map.has_key?(GlobalConstants::ROOT) if @dependency_map[GlobalConstants::ROOT].has_key? GlobalConstants::PROJECTNAME root_node = Hashit.new @dependency_map[GlobalConstants::ROOT] root_node end end end |
#traverse {|current| ... } ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dependency_tree.rb', line 67 def traverse current = GlobalConstants::ROOT current = @dependency_map[current] current = Hashit.new current yield current while current != nil begin current = next_node current.project_name rescue #puts $! current = nil end yield current if !current.nil? end end |