class Dependy::Graph::Graph

Public Class Methods

new(parent_child_list = []) click to toggle source
# File lib/dependy/graph/graph.rb, line 4
def initialize(parent_child_list = [])
  parent_child_list.each do |parent, child|
    add_node_to_graph(parent)
    add_node_to_graph(child)
    add_relationship_between(parent, child)
  end
end

Public Instance Methods

children_for(node_name) click to toggle source
# File lib/dependy/graph/graph.rb, line 16
def children_for(node_name)
  self[node_name][:children]
end
parents_for(node_name) click to toggle source
# File lib/dependy/graph/graph.rb, line 12
def parents_for(node_name)
  self[node_name][:parents]
end

Private Instance Methods

add_node_to_graph(node_name) click to toggle source
# File lib/dependy/graph/graph.rb, line 21
def add_node_to_graph(node_name)
  self[node_name] = {parents: [], children: []} unless has_key?(node_name)
end
add_relationship_between(parent, child) click to toggle source
# File lib/dependy/graph/graph.rb, line 25
def add_relationship_between(parent, child)
  self[parent][:children] << child
  self[child][:parents] << parent
end