Class: Mementus::Graph

Inherits:
Object
  • 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



49
50
51
# File 'lib/mementus/graph.rb', line 49

def adjacent(id)
  @structure.adjacent(id)
end

#directed?Boolean

Returns:

  • (Boolean)


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

def directed?
  @structure.directed?
end

#each_adjacent(node, &blk) ⇒ Object



57
58
59
# File 'lib/mementus/graph.rb', line 57

def each_adjacent(node, &blk)
  @structure.each_adjacent(node, &blk)
end

#each_edge(&blk) ⇒ Object



61
62
63
# File 'lib/mementus/graph.rb', line 61

def each_edge(&blk)
  @structure.each_edge(&blk)
end

#each_node(&blk) ⇒ Object



53
54
55
# File 'lib/mementus/graph.rb', line 53

def each_node(&blk)
  @structure.each_node(&blk)
end

#edges_countObject



21
22
23
# File 'lib/mementus/graph.rb', line 21

def edges_count
  @structure.edges_count
end

#has_edge?(edge) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mementus/graph.rb', line 37

def has_edge?(edge)
  @structure.has_edge?(edge)
end

#has_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_node?(node)
  @structure.has_node?(node)
end

#n(id) ⇒ Object



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

def n(id)
  Processor.new(self, Pipes::Node.new(id))
end

#node(id) ⇒ Object



41
42
43
# File 'lib/mementus/graph.rb', line 41

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

#nodesObject



45
46
47
# File 'lib/mementus/graph.rb', line 45

def nodes
  @structure.nodes
end

#nodes_countObject



17
18
19
# File 'lib/mementus/graph.rb', line 17

def nodes_count
  @structure.nodes_count
end

#queryObject



13
14
15
# File 'lib/mementus/graph.rb', line 13

def query
  Query::Source.new(self)
end