graphgem 0.1.12 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graph.rb +7 -13
- data/lib/node/graph_node.rb +4 -10
- 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: df729ecfd9ac9909d27684c5c75e8ad664e94435
|
4
|
+
data.tar.gz: 9dc3b5c6d96063a4e914f45241312f131ce0c992
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 091786b12a7e5220df9572f1c1592069f35a983e6c25657f43c0e9481ff0f32f29d9de3984ff632495c47341a070cf0658f864fac7a75bf792c0dbe84b10c412
|
7
|
+
data.tar.gz: e27948791dac22f19566a7cd6c7abe4aa147d090622be2d5e3e4d9de58eae62b886e136b685d7b1d48af76d6eb5a0930374fceb335da58a78413d01a6f0ceb95
|
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[name] = GraphNode.new(name, content)
|
14
14
|
end
|
15
15
|
|
16
16
|
# returns true if added
|
@@ -21,17 +21,11 @@ class Graph
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def isNode? name
|
24
|
-
@nodes
|
25
|
-
return true if n.name == name
|
26
|
-
end
|
27
|
-
return false
|
24
|
+
return @nodes[name] != nil
|
28
25
|
end
|
29
26
|
|
30
27
|
def getNode name
|
31
|
-
@nodes
|
32
|
-
return n if n.name == name
|
33
|
-
end
|
34
|
-
return nil
|
28
|
+
return @nodes[name]
|
35
29
|
end
|
36
30
|
|
37
31
|
def getConnectionWeight from, to
|
@@ -66,9 +60,9 @@ class Graph
|
|
66
60
|
|
67
61
|
def convertToCSVString
|
68
62
|
result = "From,FromContent,To,ToContent,Weight\n"
|
69
|
-
@nodes.each do |n|
|
70
|
-
n.connections.each do |c|
|
71
|
-
result += n.name + ',' + n.content + ',' + c.to.name + ',' + c.to.content + ',' + c.weight + "\n"
|
63
|
+
@nodes.each do |key, n|
|
64
|
+
n.connections.each do |key, c|
|
65
|
+
result += n.name + ',' + n.content + ',' + c.to.name + ',' + c.to.content + ',' + c.weight.to_s + "\n"
|
72
66
|
end
|
73
67
|
end
|
74
68
|
return result
|
data/lib/node/graph_node.rb
CHANGED
@@ -9,25 +9,19 @@ 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[to] = Connection.new(to,weight)
|
18
18
|
end
|
19
19
|
|
20
20
|
def getConnection name
|
21
|
-
@connections
|
22
|
-
return c if c.to.name == name
|
23
|
-
end
|
24
|
-
return nil
|
21
|
+
return @connections[name]
|
25
22
|
end
|
26
23
|
|
27
24
|
def connectedTo? name
|
28
|
-
|
29
|
-
return true if c.to.name == name
|
30
|
-
end
|
31
|
-
return false
|
25
|
+
return getConnection(name) != nil
|
32
26
|
end
|
33
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphgem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Huelsman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple gem to give a predefined interface for dealing with graphs
|
14
14
|
email: michael.huelsman@gmail.com
|