larynx 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -37
- data/lib/larynx/form.rb +1 -0
- data/lib/larynx/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -27,45 +27,45 @@ Simplest possible
|
|
27
27
|
|
28
28
|
Using the bare Application class, below is a guessing game.
|
29
29
|
|
30
|
-
class Guess < Larynx::Application
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
30
|
+
class Guess < Larynx::Application
|
31
|
+
def run
|
32
|
+
@number = rand(9) + 1
|
33
|
+
@guess = ''
|
34
|
+
@guesses = 0
|
35
|
+
get_guess
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_guess
|
39
|
+
if @guesses < 3
|
40
|
+
speak(guess_prompt) { @guesses += 1 }
|
41
|
+
else
|
42
|
+
speak "Sorry you didn't guess it. It was #{@number}. Try again soon.", :bargein => false
|
43
|
+
hangup
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def guess_prompt
|
48
|
+
@guesses == 0 ? 'Guess a number between 1 and 9.' : 'Have another guess.'
|
49
|
+
end
|
50
|
+
|
51
|
+
def check_guess
|
52
|
+
if @guess.to_i == @number
|
53
|
+
speak "You got it! It was #{@guess}. It took you #{@guesses} guesses.", :bargein => false
|
54
|
+
speak "Thanks for playing."
|
55
|
+
hangup
|
56
|
+
else
|
57
|
+
speak "No it's not #{@guess}."
|
58
|
+
get_guess
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def dtmf_received(input)
|
63
|
+
@guess = input
|
64
|
+
check_guess
|
65
|
+
end
|
49
66
|
end
|
50
67
|
|
51
|
-
|
52
|
-
if @guess.to_i == @number
|
53
|
-
speak "You got it! It was #{@guess}. It took you #{@guesses} guesses.", :bargein => false
|
54
|
-
speak "Thanks for playing."
|
55
|
-
hangup
|
56
|
-
else
|
57
|
-
speak "No it's not #{@guess}."
|
58
|
-
get_guess
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def dtmf_received(input)
|
63
|
-
@guess = input
|
64
|
-
check_guess
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
Larynx.answer {|call| Guess.run(call) }
|
68
|
+
Larynx.answer {|call| Guess.run(call) }
|
69
69
|
|
70
70
|
A more sophisticated example using the Form class
|
71
71
|
|
data/lib/larynx/form.rb
CHANGED
data/lib/larynx/version.rb
CHANGED