pie 0.2 → 0.2.1
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/lib/direction.rb~ +61 -0
- data/lib/place.rb +1 -1
- data/lib/place.rb~ +47 -0
- metadata +5 -2
data/lib/direction.rb~
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Pie
|
2
|
+
class String
|
3
|
+
def dead_end?
|
4
|
+
true
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class DeadEnd < String
|
9
|
+
def dead_end?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Direction < String
|
15
|
+
def opposite(display_name = nil)
|
16
|
+
if display_name
|
17
|
+
@display_name = display_name
|
18
|
+
else
|
19
|
+
@display_name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def dead_end?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def direction(forward, back)
|
28
|
+
dir = Direction.new(forward)
|
29
|
+
dir.opposite(back)
|
30
|
+
dir
|
31
|
+
end
|
32
|
+
|
33
|
+
def north
|
34
|
+
@north ||= direction('Go North', 'Go South')
|
35
|
+
end
|
36
|
+
|
37
|
+
def south
|
38
|
+
@south ||= direction('Go South', 'Go North')
|
39
|
+
end
|
40
|
+
def east
|
41
|
+
@east ||= direction('Go East', 'Go West')
|
42
|
+
end
|
43
|
+
def west
|
44
|
+
@west ||= direction('Go West', 'Go East')
|
45
|
+
end
|
46
|
+
def dead_end(name)
|
47
|
+
DeadEnd.new(name)
|
48
|
+
end
|
49
|
+
def north!
|
50
|
+
dead_end(north)
|
51
|
+
end
|
52
|
+
def south!
|
53
|
+
dead_end(south)
|
54
|
+
end
|
55
|
+
def east!
|
56
|
+
dead_end(east)
|
57
|
+
end
|
58
|
+
def west!
|
59
|
+
dead_end(west)
|
60
|
+
end
|
61
|
+
end
|
data/lib/place.rb
CHANGED
@@ -17,7 +17,7 @@ class Pie::Place
|
|
17
17
|
def path(nodes)
|
18
18
|
nodes.each do |place_name, direction|
|
19
19
|
paths[place_name] = direction
|
20
|
-
places[place_name].paths[name] = direction.opposite unless direction.dead_end?
|
20
|
+
places[place_name].paths[name] = direction.opposite unless !direction.respond_to?(:dead_end?) || direction.dead_end?
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/lib/place.rb~
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class Pie::Place
|
2
|
+
|
3
|
+
attr_reader :name, :description, :paths
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@paths = {}
|
7
|
+
extract_standard_options(options)
|
8
|
+
extract_name_and_description(options)
|
9
|
+
build_place_method
|
10
|
+
register_place
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
@name
|
15
|
+
end
|
16
|
+
|
17
|
+
def path(nodes)
|
18
|
+
nodes.each do |place_name, direction|
|
19
|
+
paths[place_name] = direction
|
20
|
+
places[place_name].paths[name] = direction.opposite unless direction.dead_end? || !direction.respond_to?(:dead_end?)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def extract_name_and_description(options)
|
27
|
+
raise "You seem to have extras option in this place!" unless options.length == 1
|
28
|
+
@name = options.keys.first
|
29
|
+
@description = options.values.first
|
30
|
+
end
|
31
|
+
|
32
|
+
def extract_standard_options(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_place_method
|
36
|
+
Pie.module_eval %{
|
37
|
+
def #{name}
|
38
|
+
places[:#{name}]
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def register_place
|
44
|
+
places[name] = self
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
CHANGED
@@ -5,10 +5,11 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
9
10
|
platform: ruby
|
10
11
|
authors:
|
11
|
-
- Sarah Allen, Sarah Mei
|
12
|
+
- Sarah Allen, Sarah Mei, Rich Kilmer
|
12
13
|
autorequire:
|
13
14
|
bindir: bin
|
14
15
|
cert_chain: []
|
@@ -27,11 +28,13 @@ extra_rdoc_files: []
|
|
27
28
|
|
28
29
|
files:
|
29
30
|
- lib/direction.rb
|
31
|
+
- lib/direction.rb~
|
30
32
|
- lib/pie.rb
|
31
33
|
- lib/pie.rb~
|
32
34
|
- lib/pie_server.rb
|
33
35
|
- lib/pie_server.rb~
|
34
36
|
- lib/place.rb
|
37
|
+
- lib/place.rb~
|
35
38
|
- bin/pie
|
36
39
|
- bin/pie~
|
37
40
|
- views/full_screen.erb
|