mementus 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mementus/edge.rb +23 -2
- data/lib/mementus/graph.rb +12 -0
- data/lib/mementus/node.rb +9 -1
- data/lib/mementus/version.rb +1 -1
- data/spec/graph_spec.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92652ba97da7674692fac49d6ea139aeb9c680d5
|
4
|
+
data.tar.gz: 5ea49d59abd929eb237956e2dea519e1300e94c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bf3f09c02410fbc0070d40d0016d5161f57cecf975a660ccedebcb0d10fdebdf11e01cf63e350d1fc9d33fface9ebc81d9b64002dba5911221d4dd1a6f2b3c5
|
7
|
+
data.tar.gz: c36019eb7529244bf07b4f5c1654c87e5d55c6e675e16bd82fcdce6fccb12a328d78595170b3dc698b4a41a37967c4b437c0d19c945a0bba5e3b3d0c50cb5589
|
data/lib/mementus/edge.rb
CHANGED
@@ -1,10 +1,31 @@
|
|
1
1
|
module Mementus
|
2
2
|
class Edge
|
3
|
-
attr_reader :from, :to
|
3
|
+
attr_reader :from, :to, :label
|
4
4
|
|
5
|
-
def initialize(from, to)
|
5
|
+
def initialize(from=nil, to=nil, label=:edge)
|
6
6
|
@from = from
|
7
7
|
@to = to
|
8
|
+
@label = label
|
9
|
+
end
|
10
|
+
|
11
|
+
def from=(node, label=:node)
|
12
|
+
if node.is_a?(Node)
|
13
|
+
@from = node
|
14
|
+
else
|
15
|
+
@from = Node.new(node, label)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def to=(node)
|
20
|
+
if node.is_a?(Node)
|
21
|
+
@to = node
|
22
|
+
else
|
23
|
+
@to = Node.new(node, label)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def label=(label)
|
28
|
+
@label = label
|
8
29
|
end
|
9
30
|
|
10
31
|
def nodes
|
data/lib/mementus/graph.rb
CHANGED
@@ -25,6 +25,18 @@ module Mementus
|
|
25
25
|
@index[node] ||= Set.new
|
26
26
|
end
|
27
27
|
|
28
|
+
def create_edge(&block)
|
29
|
+
edge = Edge.new
|
30
|
+
yield edge
|
31
|
+
add_edge(edge)
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_node(&block)
|
35
|
+
node = Node.new
|
36
|
+
yield node
|
37
|
+
add_node(node)
|
38
|
+
end
|
39
|
+
|
28
40
|
def add_edge(edge)
|
29
41
|
add_node(edge.from)
|
30
42
|
add_node(edge.to)
|
data/lib/mementus/node.rb
CHANGED
@@ -2,9 +2,17 @@ module Mementus
|
|
2
2
|
class Node
|
3
3
|
attr_reader :id, :label
|
4
4
|
|
5
|
-
def initialize(id, label)
|
5
|
+
def initialize(id=nil, label=:node)
|
6
6
|
@id = id
|
7
7
|
@label = label
|
8
8
|
end
|
9
|
+
|
10
|
+
def id=(id)
|
11
|
+
@id = id
|
12
|
+
end
|
13
|
+
|
14
|
+
def label=(label)
|
15
|
+
@label = label
|
16
|
+
end
|
9
17
|
end
|
10
18
|
end
|
data/lib/mementus/version.rb
CHANGED
data/spec/graph_spec.rb
CHANGED
@@ -16,6 +16,17 @@ describe Mementus::Graph do
|
|
16
16
|
expect(graph.edges_count).to eq(0)
|
17
17
|
end
|
18
18
|
|
19
|
+
specify '#create_node' do
|
20
|
+
graph = Mementus::Graph.new
|
21
|
+
graph.create_node do |node|
|
22
|
+
node.id = 1
|
23
|
+
node.label = :vertex
|
24
|
+
end
|
25
|
+
|
26
|
+
expect(graph.nodes_count).to eq(1)
|
27
|
+
expect(graph.edges_count).to eq(0)
|
28
|
+
end
|
29
|
+
|
19
30
|
specify '#add_edge' do
|
20
31
|
graph = Mementus::Graph.new
|
21
32
|
graph.add_edge(Mementus::Edge.new(Mementus::Node.new(1, :node), Mementus::Node.new(2, :node)))
|
@@ -24,6 +35,18 @@ describe Mementus::Graph do
|
|
24
35
|
expect(graph.edges_count).to eq(1)
|
25
36
|
end
|
26
37
|
|
38
|
+
specify '#create_edge' do
|
39
|
+
graph = Mementus::Graph.new
|
40
|
+
graph.create_edge do |edge|
|
41
|
+
edge.label = :relationship
|
42
|
+
edge.from = "A"
|
43
|
+
edge.to = "B"
|
44
|
+
end
|
45
|
+
|
46
|
+
expect(graph.nodes_count).to eq(2)
|
47
|
+
expect(graph.edges_count).to eq(1)
|
48
|
+
end
|
49
|
+
|
27
50
|
specify '#has_node?' do
|
28
51
|
graph = Mementus::Graph.new
|
29
52
|
node = Mementus::Node.new(1, :node)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mementus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maetl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|