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
22 23 24 25 |
# File 'lib/mementus/graph_builder.rb', line 22 def add_edge(id: nil, from: nil, to: nil, label: nil, props: {}) id = @edge_ids.next_id unless id @structure.set_edge(Edge.new(id: id, from: from, to: to, label: label, props: props)) end |
#add_node(id: nil, label: nil, props: {}) ⇒ Object
17 18 19 20 |
# File 'lib/mementus/graph_builder.rb', line 17 def add_node(id: nil, label: nil, props: {}) id = @node_ids.next_id unless id @structure.set_node(Node.new(id: id, label: label, props: props)) end |
#create_edge {|builder| ... } ⇒ Object
34 35 36 37 38 39 |
# File 'lib/mementus/graph_builder.rb', line 34 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
27 28 29 30 31 32 |
# File 'lib/mementus/graph_builder.rb', line 27 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
41 42 43 |
# File 'lib/mementus/graph_builder.rb', line 41 def graph @structure end |
#set_edge(edge) ⇒ Object
13 14 15 |
# File 'lib/mementus/graph_builder.rb', line 13 def set_edge(edge) @structure.set_edge(edge) end |
#set_node(node) ⇒ Object
9 10 11 |
# File 'lib/mementus/graph_builder.rb', line 9 def set_node(node) @structure.set_node(node) end |