Sha256: e75acf8e72c6822de6811793ca3624087ca606b0fcff18d5d601bea679670e13

Contents?: true

Size: 767 Bytes

Versions: 7

Compression:

Stored size: 767 Bytes

Contents

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 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 dtmf_received(input)
		@guess = input
		check_guess
	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.rb
larynx-0.1.5 examples/guess.rb
larynx-0.1.4 examples/guess.rb
larynx-0.1.3 examples/guess.rb
larynx-0.1.2 examples/guess.rb
larynx-0.1.1 examples/guess.rb
larynx-0.1.0 examples/guess.rb