Class: Mementus::GraphBuilder
- Inherits:
-
Object
- Object
- Mementus::GraphBuilder
- Defined in:
- lib/mementus/graph_builder.rb
Instance Method Summary collapse
- #add_edge(id: nil, from: nil, to: nil, label: nil, props: {}) ⇒ Object
- #add_node(id: nil, label: nil, props: {}) ⇒ Object
- #create_edge {|builder| ... } ⇒ Object
- #create_node {|builder| ... } ⇒ Object
- #graph ⇒ Object
-
#initialize(is_directed) ⇒ GraphBuilder
constructor
A new instance of GraphBuilder.
- #set_edge(edge) ⇒ Object
- #set_node(node) ⇒ Object
Constructor Details
#initialize(is_directed) ⇒ GraphBuilder
Returns a new instance of GraphBuilder.
3 4 5 6 7 |
# File 'lib/mementus/graph_builder.rb', line 3 def initialize(is_directed) @structure = Structure::IncidenceList.new(is_directed) @node_ids = IntegerId.new @edge_ids = IntegerId.new end |
Instance Method Details
#add_edge(id: nil, from: nil, to: nil, label: nil, props: {}) ⇒ Object
24 25 26 27 |
# File 'lib/mementus/graph_builder.rb', line 24 def add_edge(id: nil, from: nil, to: nil, label: nil, props: {}) id = @edge_ids.next_id unless id set_edge(Edge.new(id: id, from: from, to: to, label: label, props: props)) end |
#add_node(id: nil, label: nil, props: {}) ⇒ Object
19 20 21 22 |
# File 'lib/mementus/graph_builder.rb', line 19 def add_node(id: nil, label: nil, props: {}) id = @node_ids.next_id unless id set_node(Node.new(id: id, label: label, props: props)) end |
#create_edge {|builder| ... } ⇒ Object
36 37 38 39 40 41 |
# File 'lib/mementus/graph_builder.rb', line 36 def create_edge(&block) builder = EdgeBuilder.new yield builder builder.id = @edge_ids.next_id unless builder.id set_edge(builder.to_edge) end |
#create_node {|builder| ... } ⇒ Object
29 30 31 32 33 34 |
# File 'lib/mementus/graph_builder.rb', line 29 def create_node(&block) builder = NodeBuilder.new yield builder builder.id = @node_ids.next_id unless builder.id set_node(builder.to_node) end |
#graph ⇒ Object
43 44 45 |
# File 'lib/mementus/graph_builder.rb', line 43 def graph @structure end |
#set_edge(edge) ⇒ Object
14 15 16 17 |
# File 'lib/mementus/graph_builder.rb', line 14 def set_edge(edge) @structure.set_edge(edge) edge end |
#set_node(node) ⇒ Object
9 10 11 12 |
# File 'lib/mementus/graph_builder.rb', line 9 def set_node(node) @structure.set_node(node) node end |