graphgem 0.1.2 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graph.rb +13 -8
- data/lib/node/graph_node.rb +10 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fd4465d677c433676621aeac3779e4944941296
|
4
|
+
data.tar.gz: f6d682d0f8ac89c2cd46c65b7e64d4f64638bc35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88e67ccc794327e76912d4505f37dceb472da8d34a1a8d89fa0994ffe3e1d7ef2e67adb5b3fa9a398057579d94f85ad35c8ce5fa8874226eb8a7c26639beb7de
|
7
|
+
data.tar.gz: a4ad6e907ef18b3c0dfc8348b5bb9b21aee61dd17ea351a1c095be206d167ce3197447bab941155a50ff111a272e5dce12f4c50417b7b5b53fa188da14dad819
|
data/lib/graph.rb
CHANGED
@@ -6,11 +6,11 @@ class Graph
|
|
6
6
|
|
7
7
|
# creates a blank graph
|
8
8
|
def initialize
|
9
|
-
@nodes =
|
9
|
+
@nodes = []
|
10
10
|
end
|
11
11
|
|
12
12
|
def addNode name, content
|
13
|
-
@nodes
|
13
|
+
@nodes.push(GraphNode.new(name, content))
|
14
14
|
end
|
15
15
|
|
16
16
|
# returns true if added
|
@@ -21,16 +21,21 @@ class Graph
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def isNode? name
|
24
|
-
|
24
|
+
@nodes.each do |n|
|
25
|
+
return true if n.name == name
|
26
|
+
end
|
27
|
+
return false
|
25
28
|
end
|
26
29
|
|
27
30
|
def getNode name
|
28
|
-
|
31
|
+
@nodes.each do |n|
|
32
|
+
return n if n.name == name
|
33
|
+
end
|
34
|
+
return nil
|
29
35
|
end
|
30
36
|
|
31
37
|
def getConnectionWeight from, to
|
32
38
|
return nil if !isNode?(from) || !isNode?(to)
|
33
|
-
return nil if !isConnected?(from,to)
|
34
39
|
return getNode(from).getConnection(to).weight
|
35
40
|
end
|
36
41
|
|
@@ -60,9 +65,9 @@ class Graph
|
|
60
65
|
|
61
66
|
def convertToCSVString
|
62
67
|
result = "From,FromContent,To,ToContent,Weight\n"
|
63
|
-
@nodes.each do |
|
64
|
-
n.connections.each do |
|
65
|
-
result += n.name + ',' + n.content + ',' + c.to.name + ',' + c.to.content + ',' + c.weight
|
68
|
+
@nodes.each do |n|
|
69
|
+
n.connections.each do |c|
|
70
|
+
result += n.name + ',' + n.content + ',' + c.to.name + ',' + c.to.content + ',' + c.weight + "\n"
|
66
71
|
end
|
67
72
|
end
|
68
73
|
return result
|
data/lib/node/graph_node.rb
CHANGED
@@ -9,19 +9,25 @@ class GraphNode
|
|
9
9
|
def initialize name, content
|
10
10
|
@name = name
|
11
11
|
@content = content
|
12
|
-
@connections =
|
12
|
+
@connections = []
|
13
13
|
@marked = false
|
14
14
|
end
|
15
15
|
|
16
16
|
def addConnection to, weight
|
17
|
-
@connections
|
17
|
+
@connections.push(Connection.new(to, weight))
|
18
18
|
end
|
19
19
|
|
20
20
|
def getConnection name
|
21
|
-
|
21
|
+
@connections.each do |c|
|
22
|
+
return c if c.to.name == name
|
23
|
+
end
|
24
|
+
return nil
|
22
25
|
end
|
23
26
|
|
24
27
|
def connectedTo? name
|
25
|
-
|
28
|
+
@connections.each do |c|
|
29
|
+
return true if c.to.name == name
|
30
|
+
end
|
31
|
+
return false
|
26
32
|
end
|
27
33
|
end
|