Class: Mementus::Graph
- Inherits:
-
Object
show all
- Defined in:
- lib/mementus/graph.rb
Instance Method Summary
collapse
Constructor Details
#initialize(is_directed = true, &block) ⇒ Graph
Returns a new instance of Graph.
5
6
7
8
9
10
11
|
# File 'lib/mementus/graph.rb', line 5
def initialize(is_directed=true, &block)
builder = GraphBuilder.new(is_directed)
builder.instance_eval(&block) if block_given?
@structure = builder.graph
end
|
Instance Method Details
#adjacent(id) ⇒ Object
55
56
57
|
# File 'lib/mementus/graph.rb', line 55
def adjacent(id)
@structure.adjacent(id)
end
|
#adjacent_edges(id) ⇒ Object
59
60
61
|
# File 'lib/mementus/graph.rb', line 59
def adjacent_edges(id)
@structure.adjacent_edges(id)
end
|
#directed? ⇒ Boolean
21
22
23
|
# File 'lib/mementus/graph.rb', line 21
def directed?
@structure.directed?
end
|
#each_adjacent(node, &blk) ⇒ Object
67
68
69
|
# File 'lib/mementus/graph.rb', line 67
def each_adjacent(node, &blk)
@structure.each_adjacent(node, &blk)
end
|
#each_edge(&blk) ⇒ Object
71
72
73
|
# File 'lib/mementus/graph.rb', line 71
def each_edge(&blk)
@structure.each_edge(&blk)
end
|
#each_node(&blk) ⇒ Object
63
64
65
|
# File 'lib/mementus/graph.rb', line 63
def each_node(&blk)
@structure.each_node(&blk)
end
|
#edge(id) ⇒ Object
47
48
49
|
# File 'lib/mementus/graph.rb', line 47
def edge(id)
@structure.edge(id)
end
|
#edges_count ⇒ Object
17
18
19
|
# File 'lib/mementus/graph.rb', line 17
def edges_count
@structure.edges_count
end
|
#has_edge?(edge) ⇒ Boolean
39
40
41
|
# File 'lib/mementus/graph.rb', line 39
def has_edge?(edge)
@structure.has_edge?(edge)
end
|
#has_node?(node) ⇒ Boolean
35
36
37
|
# File 'lib/mementus/graph.rb', line 35
def has_node?(node)
@structure.has_node?(node)
end
|
#n(match) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/mementus/graph.rb', line 25
def n(match)
if match.is_a?(Hash)
source = nodes(match)
else
source = [node(match)]
end
Pipeline::Step.new(source, Pipeline::Pipe.new(self), self)
end
|
#node(id) ⇒ Object
43
44
45
|
# File 'lib/mementus/graph.rb', line 43
def node(id)
@structure.node(id)
end
|
#nodes(match = nil) ⇒ Object
51
52
53
|
# File 'lib/mementus/graph.rb', line 51
def nodes(match=nil)
@structure.nodes(match)
end
|
#nodes_count ⇒ Object
13
14
15
|
# File 'lib/mementus/graph.rb', line 13
def nodes_count
@structure.nodes_count
end
|