Module: Pie
- Defined in:
- lib/pie.rb,
lib/direction.rb
Defined Under Namespace
Classes: Direction, Place, WebApp
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
61
62
63
64
65
|
# File 'lib/pie.rb', line 61
def method_missing name
place = places[name.to_sym]
raise NoMethodError, "NoMethodError: Pie was expecting a place named '#{name}', but we've only got places named: #{places.keys.join(', ')}" if place.nil?
place
end
|
Instance Attribute Details
#places ⇒ Object
Returns the value of attribute places.
2
3
4
|
# File 'lib/pie.rb', line 2
def places
@places
end
|
Class Method Details
.[](key) ⇒ Object
7
8
9
|
# File 'lib/pie.rb', line 7
def self.[](key)
(@map ||= {})[key]
end
|
.[]=(key, value) ⇒ Object
11
12
13
|
# File 'lib/pie.rb', line 11
def self.[]=(key, value)
(@map ||= {})[key] = value
end
|
.language=(language) ⇒ Object
15
16
17
|
# File 'lib/pie.rb', line 15
def self.language=(language)
@language = language
end
|
.localized(id) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/pie.rb', line 19
def self.localized(id)
@values ||= {
:japanese => {
:go_north => "Go North (in jp!)",
:go_south => "Go South (in jp!)",
:go_east => "Go East (in jp!)",
:go_west => "Go West (in jp!)"
},
:english => {
:go_north => "Go North",
:go_south => "Go South",
:go_east => "Go East",
:go_west => "Go West"
}
}
@values[@language || :english][id]
end
|
.places ⇒ Object
37
38
39
|
# File 'lib/pie.rb', line 37
def self.places
Pie[:places] ||= {}
end
|
Instance Method Details
#current_image ⇒ Object
75
76
77
|
# File 'lib/pie.rb', line 75
def current_image
images[current_place.name] if current_place
end
|
#current_place(name = nil) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/pie.rb', line 67
def current_place(name=nil)
if name
Pie[:current_place] = places[name.to_sym]
else
Pie[:current_place]
end
end
|
#dead_end(name) ⇒ Object
23
24
25
|
# File 'lib/direction.rb', line 23
def dead_end(name)
direction(name)
end
|
#direction(forward, back = nil) ⇒ Object
17
18
19
20
21
|
# File 'lib/direction.rb', line 17
def direction(forward, back = nil)
dir = Direction.new(forward)
dir.opposite(back) if back
dir
end
|
#east ⇒ Object
35
36
37
|
# File 'lib/direction.rb', line 35
def east
@east ||= direction(Pie.localized(:go_east), Pie.localized(:go_west))
end
|
#east! ⇒ Object
51
52
53
|
# File 'lib/direction.rb', line 51
def east!
dead_end(east)
end
|
#image(image_maps) ⇒ Object
53
54
55
|
# File 'lib/pie.rb', line 53
def image(image_maps)
images.merge!(image_maps)
end
|
#images ⇒ Object
49
50
51
|
# File 'lib/pie.rb', line 49
def images
Pie[:images] ||= {}
end
|
#initialize ⇒ Object
4
5
6
|
# File 'lib/pie.rb', line 4
def initialize
@places = {}
end
|
#language(language) ⇒ Object
79
80
81
|
# File 'lib/pie.rb', line 79
def language(language)
Pie.language = language
end
|
#north ⇒ Object
27
28
29
|
# File 'lib/direction.rb', line 27
def north
@north ||= direction(Pie.localized(:go_north), Pie.localized(:go_south))
end
|
#north! ⇒ Object
43
44
45
|
# File 'lib/direction.rb', line 43
def north!
dead_end(north)
end
|
#place(options) ⇒ Object
57
58
59
|
# File 'lib/pie.rb', line 57
def place(options)
Place.new(places, options)
end
|
#south ⇒ Object
31
32
33
|
# File 'lib/direction.rb', line 31
def south
@south ||= direction(Pie.localized(:go_south), Pie.localized(:go_north))
end
|
#south! ⇒ Object
47
48
49
|
# File 'lib/direction.rb', line 47
def south!
dead_end(south)
end
|
#template(name = nil) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/pie.rb', line 41
def template(name = nil)
if name
Pie[:template] = name.to_sym
else
Pie[:template] || :image_page
end
end
|
#west ⇒ Object
39
40
41
|
# File 'lib/direction.rb', line 39
def west
@west ||= direction(Pie.localized(:go_west), Pie.localized(:go_east))
end
|
#west! ⇒ Object
55
56
57
|
# File 'lib/direction.rb', line 55
def west!
dead_end(west)
end
|