Class: Mementus::Graph
- Inherits:
-
Object
show all
- Defined in:
- lib/mementus/graph.rb
Instance Method Summary
collapse
Constructor Details
#initialize(is_mutable: false, is_directed: true, &block) ⇒ Graph
Returns a new instance of Graph.
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/mementus/graph.rb', line 3
def initialize(is_mutable: false, is_directed: true, &block)
builder = GraphBuilder.new(is_directed)
BindingDelegator.new(builder, block.binding).instance_eval(&block) if block_given?
@structure = builder.graph
if is_mutable
self.class.include Mutators
@node_ids = IntegerId.new(builder.next_node_id)
@edge_ids = IntegerId.new(builder.next_edge_id)
end
end
|
Instance Method Details
#directed? ⇒ Boolean
25
26
27
|
# File 'lib/mementus/graph.rb', line 25
def directed?
@structure.directed?
end
|
#each_edge(&blk) ⇒ Object
83
84
85
|
# File 'lib/mementus/graph.rb', line 83
def each_edge(&blk)
@structure.each_edge(&blk)
end
|
#each_node(&blk) ⇒ Object
79
80
81
|
# File 'lib/mementus/graph.rb', line 79
def each_node(&blk)
@structure.each_node(&blk)
end
|
#edge(id) ⇒ Object
51
52
53
|
# File 'lib/mementus/graph.rb', line 51
def edge(id)
@structure.edge(id)
end
|
#edges(match = nil) ⇒ Object
59
60
61
|
# File 'lib/mementus/graph.rb', line 59
def edges(match=nil)
@structure.edges(match)
end
|
#edges_count ⇒ Object
21
22
23
|
# File 'lib/mementus/graph.rb', line 21
def edges_count
@structure.edges_count
end
|
#has_edge?(edge, to = nil) ⇒ Boolean
43
44
45
|
# File 'lib/mementus/graph.rb', line 43
def has_edge?(edge, to=nil)
@structure.has_edge?(edge, to)
end
|
#has_node?(node) ⇒ Boolean
39
40
41
|
# File 'lib/mementus/graph.rb', line 39
def has_node?(node)
@structure.has_node?(node)
end
|
#incoming(id, match = nil) ⇒ Object
67
68
69
|
# File 'lib/mementus/graph.rb', line 67
def incoming(id, match=nil)
@structure.incoming(id, match)
end
|
#incoming_edges(id, match = nil) ⇒ Object
75
76
77
|
# File 'lib/mementus/graph.rb', line 75
def incoming_edges(id, match=nil)
@structure.incoming_edges(id, match)
end
|
#n(match) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/mementus/graph.rb', line 29
def n(match)
if match.is_a?(Hash) || match.is_a?(Symbol)
source = nodes(match)
else
source = [node(match)]
end
Pipeline::Step.new(source, Pipeline::Pipe.new(self), self)
end
|
#node(id) ⇒ Object
47
48
49
|
# File 'lib/mementus/graph.rb', line 47
def node(id)
@structure.node(id)
end
|
#nodes(match = nil) ⇒ Object
55
56
57
|
# File 'lib/mementus/graph.rb', line 55
def nodes(match=nil)
@structure.nodes(match)
end
|
#nodes_count ⇒ Object
17
18
19
|
# File 'lib/mementus/graph.rb', line 17
def nodes_count
@structure.nodes_count
end
|
#outgoing(id, match = nil) ⇒ Object
63
64
65
|
# File 'lib/mementus/graph.rb', line 63
def outgoing(id, match=nil)
@structure.adjacent(id, match)
end
|
#outgoing_edges(id, match = nil) ⇒ Object
71
72
73
|
# File 'lib/mementus/graph.rb', line 71
def outgoing_edges(id, match=nil)
@structure.outgoing_edges(id, match)
end
|