Class: Mementus::GraphBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mementus/graph_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(is_directed) ⇒ GraphBuilder



3
4
5
# File 'lib/mementus/graph_builder.rb', line 3

def initialize(is_directed)
  @structure = Structure::AdjacencyList.new(is_directed)
end

Instance Method Details

#add_edge(edge) ⇒ Object



23
24
25
# File 'lib/mementus/graph_builder.rb', line 23

def add_edge(edge)
  @structure.add_edge(edge)
end

#add_node(node) ⇒ Object



7
8
9
# File 'lib/mementus/graph_builder.rb', line 7

def add_node(node)
  @structure.add_node(node)
end

#create_edge {|edge| ... } ⇒ Object

Yields:

  • (edge)


11
12
13
14
15
# File 'lib/mementus/graph_builder.rb', line 11

def create_edge(&block)
  edge = EdgeBuilder.new
  yield edge
  @structure.add_edge(edge)
end

#create_node {|node| ... } ⇒ Object

Yields:

  • (node)


17
18
19
20
21
# File 'lib/mementus/graph_builder.rb', line 17

def create_node(&block)
  node = NodeBuilder.new
  yield node
  @structure.add_node(node)
end

#graphObject



27
28
29
# File 'lib/mementus/graph_builder.rb', line 27

def graph
  @structure
end