README.rdoc in larynx-0.1.0 vs README.rdoc in larynx-0.1.1
- old
+ new
@@ -25,48 +25,48 @@
call.speak 'Hello world! Or whoever you are.'
}
Using the bare Application class, below is a guessing game.
-class Guess < Larynx::Application
- def run
- @number = rand(9) + 1
- @guess = ''
- @guesses = 0
- get_guess
- end
+ class Guess < Larynx::Application
+ def run
+ @number = rand(9) + 1
+ @guess = ''
+ @guesses = 0
+ get_guess
+ end
- def get_guess
- if @guesses < 3
- speak(guess_prompt) { @guesses += 1 }
- else
- speak "Sorry you didn't guess it. It was #{@number}. Try again soon.", :bargein => false
- hangup
- end
- end
+ def get_guess
+ if @guesses < 3
+ speak(guess_prompt) { @guesses += 1 }
+ else
+ speak "Sorry you didn't guess it. It was #{@number}. Try again soon.", :bargein => false
+ hangup
+ end
+ end
- def guess_prompt
- @guesses == 0 ? 'Guess a number between 1 and 9.' : 'Have another guess.'
- end
+ def guess_prompt
+ @guesses == 0 ? 'Guess a number between 1 and 9.' : 'Have another guess.'
+ end
- def check_guess
- if @guess.to_i == @number
- speak "You got it! It was #{@guess}. It took you #{@guesses} guesses.", :bargein => false
- speak "Thanks for playing."
- hangup
- else
- speak "No it's not #{@guess}."
- get_guess
- end
- end
+ def check_guess
+ if @guess.to_i == @number
+ speak "You got it! It was #{@guess}. It took you #{@guesses} guesses.", :bargein => false
+ speak "Thanks for playing."
+ hangup
+ else
+ speak "No it's not #{@guess}."
+ get_guess
+ end
+ end
- def dtmf_received(input)
- @guess = input
- check_guess
- end
-end
+ def dtmf_received(input)
+ @guess = input
+ check_guess
+ end
+ end
-Larynx.answer {|call| Guess.run(call) }
+ Larynx.answer {|call| Guess.run(call) }
A more sophisticated example using the Form class
class Guess < Larynx::Form
field(:guess, :attempts => 3, :length => 1) do