Sha256: be7cab7c01665d76cc44d57b85dac23ffd3b2fe5bf18885c6a39b7dc0c92f9bb

Contents?: true

Size: 759 Bytes

Versions: 7

Compression:

Stored size: 759 Bytes

Contents

class Guess < Larynx::Form
	field(:guess, :attempts => 3, :length => 1) do
		prompt :speak => 'Guess a number between 1 and 9.', :interdigit_timeout => 6
		reprompt :speak => 'Have another guess.', :interdigit_timeout => 6

		setup do
			@number = rand(9) + 1
			@guesses = 0
		end

		validate do
			@guesses += 1 if guess.size > 0
			@number == guess.to_i
		end

		invalid do
			if guess.size > 0
				speak "No, it's not #{guess}.", :bargein => false
			end
		end

		success do
			speak "You got it! It was #{guess}. It took you #{@guesses} guesses.", :bargein => false
			hangup
		end

		failure do
			speak "Sorry you didn't guess it. It was #{@number}. Try again soon.", :bargein => false
			hangup
		end
	end
end

Larynx.answer {|call| Guess.run(call) }

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
larynx-0.1.6 examples/guess_form.rb
larynx-0.1.5 examples/guess_form.rb
larynx-0.1.4 examples/guess_form.rb
larynx-0.1.3 examples/guess_form.rb
larynx-0.1.2 examples/guess_form.rb
larynx-0.1.1 examples/guess_form.rb
larynx-0.1.0 examples/guess_form.rb