square_graph 0.3.0 → 1.0.0
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.
- data/README.rdoc +15 -0
- data/lib/{face.rb → square_graph/face.rb} +1 -1
- data/lib/square_graph.rb +24 -3
- data/spec/face_spec.rb +4 -4
- data/spec/square_graph_spec.rb +51 -0
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -16,6 +16,21 @@ Or you can compile the project yourself (options to install inside rake):
|
|
16
16
|
... blah blah pull stuff ...
|
17
17
|
$ rake build_gem
|
18
18
|
|
19
|
+
== How to Use
|
20
|
+
|
21
|
+
Yay, you have the gem now! Now you can include this in your projects.
|
22
|
+
|
23
|
+
Initiate a SquareGraph:
|
24
|
+
|
25
|
+
sgWithoutDimensions = SquareGraph.new
|
26
|
+
sgWithDimensions = SquareGraph.new(x, y)
|
27
|
+
|
28
|
+
Fill in faces!
|
29
|
+
|
30
|
+
SquareGraph.fill(0,0,my_sexy_object)
|
31
|
+
|
32
|
+
Have fun!
|
33
|
+
|
19
34
|
== License
|
20
35
|
|
21
36
|
Released under the MIT License. See the {LICENSE}[https://github.com/D4L/squareGraph/blob/master/LICENSE] file for further details.
|
data/lib/square_graph.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'face'
|
2
|
-
|
3
1
|
class SquareGraph
|
4
2
|
|
5
3
|
attr_reader :length, :width
|
@@ -29,6 +27,10 @@ class SquareGraph
|
|
29
27
|
|
30
28
|
def fill(x, y, o = true)
|
31
29
|
test_fixnum(x, y)
|
30
|
+
if not o
|
31
|
+
self.remove(x, y) if @sg[[x, y]]
|
32
|
+
return nil
|
33
|
+
end
|
32
34
|
if @sized == true
|
33
35
|
return nil if test_range([1, x], [1, y], [x, @length], [y, @length])
|
34
36
|
end
|
@@ -52,18 +54,25 @@ class SquareGraph
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def empty?
|
57
|
+
@sg.none?
|
58
|
+
end
|
59
|
+
|
60
|
+
def anytrue?
|
55
61
|
!(@sg.any? do |f|
|
56
62
|
@sg[f[0]] and @sg[f[0]].object
|
57
63
|
end)
|
58
64
|
end
|
59
65
|
|
60
66
|
def each_obj
|
67
|
+
return nil if @sg.empty?
|
61
68
|
@sg.each_pair do |f, o|
|
62
69
|
yield(o.object)
|
63
|
-
end
|
70
|
+
end if block_given?
|
71
|
+
@sg.each_pair if not block_given?
|
64
72
|
end
|
65
73
|
|
66
74
|
def each_pos
|
75
|
+
return nil if @sg.empty?
|
67
76
|
pos = Array.new
|
68
77
|
@length.downto(1).each do |l|
|
69
78
|
@width.downto(1).each do |w|
|
@@ -75,7 +84,17 @@ class SquareGraph
|
|
75
84
|
end
|
76
85
|
pos.each do |p|
|
77
86
|
yield(p)
|
87
|
+
end if block_given?
|
88
|
+
pos.each if not block_given?
|
89
|
+
end
|
90
|
+
|
91
|
+
def objects
|
92
|
+
rt = Array.new
|
93
|
+
@sg.values.each do |f|
|
94
|
+
rt.push (f.object)
|
78
95
|
end
|
96
|
+
return nil if rt.size == 0
|
97
|
+
rt
|
79
98
|
end
|
80
99
|
|
81
100
|
private
|
@@ -91,3 +110,5 @@ class SquareGraph
|
|
91
110
|
end
|
92
111
|
|
93
112
|
end
|
113
|
+
|
114
|
+
require 'square_graph/face'
|
data/spec/face_spec.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'face'
|
1
|
+
require 'square_graph/face'
|
2
2
|
|
3
|
-
describe Face, '#new' do
|
3
|
+
describe SquareGraph::Face, '#new' do
|
4
4
|
it "accepts an x, y, object and can display them easily" do
|
5
|
-
a = Face.new(5, 5, true)
|
5
|
+
a = SquareGraph::Face.new(5, 5, true)
|
6
6
|
a.x.should eql(5)
|
7
7
|
a.y.should eql(5)
|
8
8
|
a.object.should eql(true)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe Face, '#get_truthy' do
|
12
|
+
describe SquareGraph::Face, '#get_truthy' do
|
13
13
|
#TODO this will be fun, basically, it will get the truth value of the object
|
14
14
|
end
|
data/spec/square_graph_spec.rb
CHANGED
@@ -70,6 +70,24 @@ describe SquareGraph, "#fill, #get" do
|
|
70
70
|
sg.fill(3,3,du)
|
71
71
|
sg.get(3,3).should eql(du)
|
72
72
|
end
|
73
|
+
it "cannot fill spots with falsey things" do
|
74
|
+
sg = SquareGraph.new
|
75
|
+
sg.fill(0,0, nil).should be_nil
|
76
|
+
sg.objects.should be_nil
|
77
|
+
end
|
78
|
+
it "allows weird fills" do
|
79
|
+
sg = SquareGraph.new
|
80
|
+
du = DummyObject.new(nil)
|
81
|
+
sg.fill(0,0,du)
|
82
|
+
sg.get(0,0).value.should be_nil
|
83
|
+
end
|
84
|
+
it "can fill spots with nil to act as delete" do
|
85
|
+
sg = SquareGraph.new
|
86
|
+
sg.fill(0,0)
|
87
|
+
sg.objects.size.should eql(1)
|
88
|
+
sg.fill(0,0,nil).should be_nil
|
89
|
+
sg.empty?.should eql(true)
|
90
|
+
end
|
73
91
|
it "doesn't allow fills of outside the graph" do
|
74
92
|
sg = SquareGraph.new(5,10)
|
75
93
|
sg.fill(10, 2).should be_nil
|
@@ -173,6 +191,11 @@ describe SquareGraph, "#each_pos" do
|
|
173
191
|
end
|
174
192
|
i.should eql(1)
|
175
193
|
end
|
194
|
+
it "returns a enumerator class if run my itself" do
|
195
|
+
sg = SquareGraph.new(5,5)
|
196
|
+
sg.fill(3,3)
|
197
|
+
sg.each_pos.class.should eql(Enumerator)
|
198
|
+
end
|
176
199
|
end
|
177
200
|
|
178
201
|
describe SquareGraph, "#each_obj" do
|
@@ -194,6 +217,11 @@ describe SquareGraph, "#each_obj" do
|
|
194
217
|
end
|
195
218
|
total.should eql(15)
|
196
219
|
end
|
220
|
+
it "returns an enumerator class if run my itself" do
|
221
|
+
sg = SquareGraph.new
|
222
|
+
sg.fill(0,0)
|
223
|
+
sg.each_obj.class.should eql(Enumerator)
|
224
|
+
end
|
197
225
|
end
|
198
226
|
|
199
227
|
describe SquareGraph, "#[][]" do
|
@@ -213,3 +241,26 @@ describe SquareGraph, "#[][]=" do
|
|
213
241
|
#sg[0][0].should eql(true)
|
214
242
|
end
|
215
243
|
end
|
244
|
+
|
245
|
+
describe SquareGraph, "#objects" do
|
246
|
+
it "returns an array of all the objects" do
|
247
|
+
sg = SquareGraph.new
|
248
|
+
sg.fill(0,0)
|
249
|
+
sg.fill(2,2)
|
250
|
+
sg.fill(3,3)
|
251
|
+
sg.objects.each do |i|
|
252
|
+
i.should eql(true)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
it "returns nil if there aren't any objects" do
|
256
|
+
sg = SquareGraph.new
|
257
|
+
sg.objects.should be_nil
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe SquareGraph, "#anytrue?" do
|
262
|
+
it "requires some more truthy stuff" do
|
263
|
+
#TODO kekeke
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: square_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,15 +11,16 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
14
|
+
description: A dimensionable graph that acts kinda like a grid. You can fill in spots
|
15
|
+
with objects and then iterate over the entire grid or just objects. This is just
|
16
|
+
version 1, there will be alot of neat tricks to come.
|
16
17
|
email: Austin.L.D4L@gmail.com
|
17
18
|
executables: []
|
18
19
|
extensions: []
|
19
20
|
extra_rdoc_files: []
|
20
21
|
files:
|
21
22
|
- lib/square_graph.rb
|
22
|
-
- lib/face.rb
|
23
|
+
- lib/square_graph/face.rb
|
23
24
|
- Rakefile
|
24
25
|
- README.rdoc
|
25
26
|
- spec/square_graph_spec.rb
|