class Mementus::Graph

Public Class Methods

new(is_mutable: false, is_directed: true, &block) click to toggle source
# 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

Public Instance Methods

directed?() click to toggle source
# File lib/mementus/graph.rb, line 25
def directed?
  @structure.directed?
end
each_edge(&blk) click to toggle source
# File lib/mementus/graph.rb, line 83
def each_edge(&blk)
  @structure.each_edge(&blk)
end
each_node(&blk) click to toggle source
# File lib/mementus/graph.rb, line 79
def each_node(&blk)
  @structure.each_node(&blk)
end
edge(id) click to toggle source
# File lib/mementus/graph.rb, line 51
def edge(id)
  @structure.edge(id)
end
edges(match=nil) click to toggle source
# File lib/mementus/graph.rb, line 59
def edges(match=nil)
  @structure.edges(match)
end
edges_count() click to toggle source
# File lib/mementus/graph.rb, line 21
def edges_count
  @structure.edges_count
end
has_edge?(edge, to=nil) click to toggle source
# File lib/mementus/graph.rb, line 43
def has_edge?(edge, to=nil)
  @structure.has_edge?(edge, to)
end
has_node?(node) click to toggle source
# File lib/mementus/graph.rb, line 39
def has_node?(node)
  @structure.has_node?(node)
end
incoming(id, match=nil) click to toggle source
# File lib/mementus/graph.rb, line 67
def incoming(id, match=nil)
  @structure.incoming(id, match)
end
incoming_edges(id, match=nil) click to toggle source
# File lib/mementus/graph.rb, line 75
def incoming_edges(id, match=nil)
  @structure.incoming_edges(id, match)
end
n(match) click to toggle source
# 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) click to toggle source
# File lib/mementus/graph.rb, line 47
def node(id)
  @structure.node(id)
end
nodes(match=nil) click to toggle source
# File lib/mementus/graph.rb, line 55
def nodes(match=nil)
  @structure.nodes(match)
end
nodes_count() click to toggle source
# File lib/mementus/graph.rb, line 17
def nodes_count
  @structure.nodes_count
end
outgoing(id, match=nil) click to toggle source
# File lib/mementus/graph.rb, line 63
def outgoing(id, match=nil)
  @structure.adjacent(id, match)
end
outgoing_edges(id, match=nil) click to toggle source
# File lib/mementus/graph.rb, line 71
def outgoing_edges(id, match=nil)
  @structure.outgoing_edges(id, match)
end