zadt 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86e5ca0fd050ff281f0ca0a6bb5cc7c00b280853
4
- data.tar.gz: 888f8e20e307fdc2ee0a8cffc007428fd712fa23
3
+ metadata.gz: a5c19deae423e0c9c58bd1a0ca3426f9f5c35247
4
+ data.tar.gz: 90eccd3bfea079e453115d2f37adc811050281f6
5
5
  SHA512:
6
- metadata.gz: 5a341716b85e4e6cb204045d087b5b23254e0dba1c5abd587ce8ab82f9d6c30205b04175e620a6bc8600b3d5003f885ef6e01db38d4815a085b859376bd85d08
7
- data.tar.gz: 1a45efbc759a7b21bd9807c1c6bff9e7d89c8cc243dbea25d080d6047a32e19277b56fa37177a966f78e196e1b4e66cb2c5f0b1d7790c9a0b88703151f3065b0
6
+ metadata.gz: 06af58c05476e6e9b876aa73db9d966ec36dd28a417aff76f5dede74648627eed9a28afae75de7f874aad8efa7ac592cf821959bf35e407dfeb6ba8e4af08160
7
+ data.tar.gz: 3a3ec25e47c7c5c5c031ff03d5275b5959450fedee8176e6ea99be9b87fa2bcb91f9174078d3b0cd9401fd80ccbd55dd9fd8fdb610be4ad9110432d71e68d3e9
@@ -14,7 +14,7 @@ module Zadt
14
14
  puts "--Vertex, a 'spot' on the graph"
15
15
  puts "--Edge, connects two vertices"
16
16
  puts "-FaceGraph, a sub-class of Graph which includes Faces"
17
- puts "--Face, a space surrounded by Edges. Consists of Vertices and the Edges connecting them"
17
+ puts "--Face, a space surrounded by a cycle of Edges. Consists of Vertices and the Edges connecting them"
18
18
  puts ""
19
19
  puts "Each data type also has a help function. Type Zadt::Stack::help or Zadt::Stack::methods for a list of Stack methods, and so on for each data type."
20
20
  end
@@ -1,19 +1,23 @@
1
1
  module Zadt
2
2
  class Edge
3
- attr_accessor :connection
4
- def initialize(v1, v2)
3
+ # Made up of a
4
+ attr_reader :connection
5
+ # Contains
6
+ attr_accessor :value
7
+ def initialize(v1, v2, value = Hash.new)
5
8
  @connection = [v1, v2]
6
- end
7
-
8
- def self.help
9
- puts "Edge has one method:"
10
- puts "#connection, which returns the vertices the edge connects"
9
+ @value = value
11
10
  end
12
11
 
13
12
  def self.methods
14
13
  self.help
15
14
  end
16
15
 
16
+
17
+ def inspect
18
+ @connection.to_s
19
+ end
20
+
17
21
  def help
18
22
  self.help
19
23
  end
@@ -22,8 +26,12 @@ module Zadt
22
26
  help
23
27
  end
24
28
 
25
- def inspect
26
- @connection.to_s
29
+ def self.help
30
+ puts "Edge has one method:"
31
+ puts "#connection, which returns the vertices the edge connects"
27
32
  end
33
+
34
+ private
35
+
28
36
  end
29
37
  end
@@ -3,17 +3,22 @@
3
3
  module Zadt
4
4
  class Face
5
5
  attr_reader :edges, :vertices, :neighboring_faces
6
- def initialize(edges_array, neighboring_faces = {})
6
+ # Contains
7
+ attr_accessor :value
8
+ def initialize(edges_array, neighboring_faces = {}, value = Hash.new)
7
9
  raise "Not enough edges" if edges_array.length < 3
8
10
  @edges = edges_array
9
11
  vertices = edges_array.map{ |edge| edge.connection}.inject(:+).uniq
10
12
  @vertices = ensure_cyclic(vertices)
11
13
  @neighboring_faces = neighboring_faces
12
14
  @neighbor_id = @neighboring_faces.length
15
+ @value = value
13
16
  end
14
17
 
18
+ # TODO: Neighbors shouldn't be stored in Face, as FaceGraph takes care of this
15
19
  def self.help
16
20
  puts "Here are the functions for Face:"
21
+
17
22
  puts "#add_neighbor(face)"
18
23
  puts "#remove_neighbor(neighbor)"
19
24
  end
@@ -3,7 +3,12 @@ require_relative 'graph.rb'
3
3
 
4
4
  module Zadt
5
5
  class FaceGraph < Graph
6
+ # Made up of
6
7
  attr_reader :faces
8
+ # in addition to its parent's :vertices and :edges
9
+
10
+ # Contains
11
+ # attr_accessor :value
7
12
 
8
13
  def initialize
9
14
  #@faces is ALL faces on the graph
@@ -11,37 +16,10 @@ module Zadt
11
16
  super
12
17
  end
13
18
 
14
- def self.help
15
- puts "Here are the functions for FaceGraph:"
16
- puts "#add_face(edges_array), makes a face with the given edges (must be cyclicly connected)"
17
- puts "#make_original_face(num_edges), which makes a standard disconnected face"
18
- puts "#add_attached_face(vertex_array, num_edges), which adds a face connected to the vertex_array"
19
- puts "#find_neighbors(vertex_array), lists all faces containing the given vertices"
20
- puts "#find_face_neighbors(vertex_array), which finds all neighbors of the given face"
21
- puts "--a neighbor of a face is defined as one that shares a vertex (not necessarily an edge)"
22
- puts "#make_vertex_line(vertex_array), reorders a list of connected vertices by connection sequence"
23
- puts ""
24
- puts "FaceGraph also inherits the following functions from Graph:"
25
- puts "#add_vertex"
26
- puts "#remove_vertex(vertex)"
27
- puts "#make_connection(v1,v2), adds an edge between two vertices"
28
- puts "#break_connection(v1,v2)"
29
- puts "#find_connection(v1,v2), returns edge connecting two given vertices"
30
- puts "#is_connected?(v1,v2)"
31
- end
32
-
33
19
  def self.methods
34
20
  self.help
35
21
  end
36
22
 
37
- def help
38
- self.help
39
- end
40
-
41
- def methods
42
- help
43
- end
44
-
45
23
  def add_face(edges_array)
46
24
  face = Face.new(edges_array)
47
25
  @faces << face
@@ -142,6 +120,37 @@ module Zadt
142
120
  neighbors - [face]
143
121
  end
144
122
 
123
+ def help
124
+ FaceGraph.help
125
+ end
126
+
127
+ def methods
128
+ help
129
+ end
130
+
131
+
132
+
133
+ def self.help
134
+ puts "Here are the functions for FaceGraph:"
135
+ puts "#add_face(edges_array), makes a face with the given edges (must be cyclicly connected)"
136
+ puts "#make_original_face(num_edges), which makes a standard disconnected face"
137
+ puts "#add_attached_face(vertex_array, num_edges), which adds a face connected to the vertex_array"
138
+ puts "#find_neighbors(vertex_array), lists all faces containing the given vertices"
139
+ puts "#find_face_neighbors(vertex_array), which finds all neighbors of the given face"
140
+ puts "--a neighbor of a face is defined as one that shares a vertex (not necessarily an edge)"
141
+ puts "#make_vertex_line(vertex_array), reorders a list of connected vertices by connection sequence"
142
+ puts ""
143
+ puts "FaceGraph also inherits the following functions from Graph:"
144
+ puts "#add_vertex"
145
+ puts "#remove_vertex(vertex)"
146
+ puts "#make_connection(v1,v2), adds an edge between two vertices"
147
+ puts "#break_connection(v1,v2)"
148
+ puts "#find_connection(v1,v2), returns edge connecting two given vertices"
149
+ puts "#is_connected?(v1,v2)"
150
+ end
151
+
152
+ private
153
+
145
154
  def make_vertex_line(vertex_array)
146
155
  connection_line = []
147
156
  connection_line << vertex_array.first
@@ -158,7 +167,7 @@ module Zadt
158
167
  end
159
168
  connection_line
160
169
  end
161
- private
170
+
162
171
  def make_neighbors(face1, face2)
163
172
  face1.add_neighbor(face2)
164
173
  face2.add_neighbor(face1)
@@ -1,8 +1,15 @@
1
1
  require_relative 'vertex.rb'
2
-
2
+ require_relative 'edge.rb'
3
3
  module Zadt
4
4
  class Graph
5
- attr_reader :vertices, :edges
5
+ # Made up of
6
+ attr_reader :vertices
7
+
8
+ # Which are connected by
9
+ attr_reader :edges
10
+
11
+ # Contains
12
+ attr_accessor :value
6
13
 
7
14
  #init_v allows for initial vertices (not generally used)
8
15
  def initialize
@@ -10,30 +17,13 @@ module Zadt
10
17
  @vertices = []
11
18
  #@edges is ALL edges on the graph
12
19
  @edges = []
13
- end
14
-
15
- def self.help
16
- puts "Here are the functions for Graph:"
17
- puts "#add_vertex"
18
- puts "#remove_vertex(vertex)"
19
- puts "#make_connection(v1,v2), adds an edge between two vertices"
20
- puts "#break_connection(v1,v2)"
21
- puts "#find_connection(v1,v2), returns edge connecting two given vertices"
22
- puts "#is_connected?(v1,v2)"
20
+ @value = Hash.new
23
21
  end
24
22
 
25
23
  def self.methods
26
24
  self.help
27
25
  end
28
26
 
29
- def help
30
- self.help
31
- end
32
-
33
- def methods
34
- help
35
- end
36
-
37
27
  # Add a vertex
38
28
  def add_vertex
39
29
  vertex = Vertex.new
@@ -59,12 +49,24 @@ module Zadt
59
49
  def make_connection(v1, v2)
60
50
  raise "already connected" if is_connected?(v1, v2)
61
51
  # Connect the two using the vertex method "connect"
52
+
62
53
  edge = v1.connect(v2)
63
54
  # Add to edge catalog
64
55
  @edges << edge
65
56
  edge
66
57
  end
67
58
 
59
+ # Find the edge connecting two vertices
60
+ def find_connection(v1, v2)
61
+ connection = v1.edges.select {|edge| edge.connection.include?(v2)}
62
+ connection.first
63
+ end
64
+
65
+ # Returns whether two vertices are connected
66
+ def is_connected?(v1, v2)
67
+ v1.connections.include?(v2)
68
+ end
69
+
68
70
  def break_connection(v1, v2)
69
71
  raise "First vertex does not exist" if !v1
70
72
  raise "Second vertex does not exist" if !v2
@@ -84,15 +86,22 @@ module Zadt
84
86
  end
85
87
  end
86
88
 
87
- # Find the edge connecting two vertices
88
- def find_connection(v1, v2)
89
- connection = v1.edges.select {|edge| edge.connection.include?(v2)}
90
- connection.first
89
+ def help
90
+ Graph.help
91
91
  end
92
92
 
93
- # Returns whether two vertices are connected
94
- def is_connected?(v1, v2)
95
- v1.connections.include?(v2)
93
+ def methods
94
+ help
95
+ end
96
+
97
+ def self.help
98
+ puts "Here are the functions for Graph:"
99
+ puts "#add_vertex"
100
+ puts "#remove_vertex(vertex)"
101
+ puts "#make_connection(v1,v2), adds an edge between two vertices"
102
+ puts "#break_connection(v1,v2)"
103
+ puts "#find_connection(v1,v2), returns edge connecting two given vertices"
104
+ puts "#is_connected?(v1,v2)"
96
105
  end
97
106
  end
98
107
  end
@@ -1,39 +1,29 @@
1
- require_relative 'edge.rb'
2
1
  module Zadt
3
2
  class Vertex
4
- attr_accessor :edges, :connections
5
- def initialize
3
+ # Connected by
4
+ attr_accessor :edges
5
+
6
+ # Connected with
7
+ attr_accessor :connections
8
+
9
+ # Contains
10
+ attr_accessor :value
11
+
12
+ def initialize(value = Hash.new)
6
13
  # List of edges attached to vertex
7
14
  @edges = []
8
15
  # List of vertices "connected" to this one
9
16
  @connections = []
10
- end
11
-
12
- def self.help
13
- puts "Here are the functions for Vertex:"
14
- puts "#connect(other_vertex)"
15
- puts "#is_connected?(other_vertex)"
16
- puts "#make_connection(v1,v2)"
17
- puts "#break_connection(v1,v2)"
18
- puts "#find_connection(v1,v2)"
19
- puts "#is_connected?(v1,v2)"
17
+ @value = value
20
18
  end
21
19
 
22
20
  def self.methods
23
21
  self.help
24
22
  end
25
23
 
26
- def help
27
- self.help
28
- end
29
-
30
- def methods
31
- help
32
- end
33
-
34
24
  # Make an edge between this vertex and another
35
25
  def connect(other_vertex)
36
- return nil if !other_vertex
26
+ return nil if !other_vertex.is_a?(Vertex) || other_vertex == self
37
27
  raise "already connected" if is_connected?(other_vertex)
38
28
 
39
29
  edge = Edge.new(self, other_vertex)
@@ -51,7 +41,8 @@ module Zadt
51
41
  end
52
42
 
53
43
  def inspect
54
- "Vertex"
44
+ description = "Vertex"
45
+ description += ": empty" if @value.empty?
55
46
  end
56
47
 
57
48
  # Used to store connection info in the second vertex
@@ -62,5 +53,23 @@ module Zadt
62
53
  @connections << vertex
63
54
  end
64
55
 
56
+ def self.help
57
+ puts "Here are the functions for Vertex:"
58
+ puts "#connect(other_vertex)"
59
+ puts "#is_connected?(other_vertex)"
60
+ puts "#make_connection(v1,v2)"
61
+ puts "#break_connection(v1,v2)"
62
+ puts "#find_connection(v1,v2)"
63
+ puts "#is_connected?(v1,v2)"
64
+ end
65
+
66
+ def help
67
+ Vertex.methods
68
+ end
69
+
70
+ def methods
71
+ help
72
+ end
73
+ private
65
74
  end
66
75
  end
@@ -1,3 +1,3 @@
1
1
  module Zadt
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zadt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Zagorski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler