Module: MiniGraph

Defined in:
lib/mini_graph.rb,
lib/mini_graph/version.rb,
lib/mini_graph/core/edge.rb,
lib/mini_graph/core/error.rb,
lib/mini_graph/core/graph.rb,
lib/mini_graph/core/search.rb,
lib/mini_graph/dsl/graph_context.rb,
lib/mini_graph/dsl/search_context.rb

Defined Under Namespace

Modules: Core, DSL

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.bfs(graph, start_at: nil) ⇒ Object



33
34
35
# File 'lib/mini_graph.rb', line 33

def self.bfs(graph, start_at: nil)
  MiniGraph::DSL::SearchContext.evaluate(graph, start_at, algorithm: :bfs)
end

.create(*vertices, &block) ⇒ Object

Used to construct a new graph.

Example usage:

jim   = Person.new
john  = Person.new
jill  = Person.new
jane  = Person.new

friends = MiniGraph.create(jim, john, jill, jane) do
  # Creates a directed graph
  directed!

  edge from: jim,   to: [john, jill, jane]
  edge from: john,  to: [jill, jane]
  edge from: jane,  to: jill
end


25
26
27
# File 'lib/mini_graph.rb', line 25

def self.create(*vertices, &block)
  MiniGraph::DSL::GraphContext.evaluate(*vertices, &block)
end

.dfs(graph, start_at: nil) ⇒ Object



29
30
31
# File 'lib/mini_graph.rb', line 29

def self.dfs(graph, start_at: nil)
  MiniGraph::DSL::SearchContext.evaluate(graph, start_at, algorithm: :dfs)
end