Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1 CHANGELOG.md
@@ -7,6 +7,7 @@
* Feature: `CallControll#join` can be made non-blocking by passing `:async => true`
* Feature: `CallController#ask` now supports `:terminator` and `:limit` options to add early termination by terminator digit or digit limit conditions
* Feature: `CallController#ask` may now have prompt interruptibility configured using `:interruptible => false`
+ * Change: `CallController#ask` now returns a menu object for establishing completion mode, input buffer (#result), etc
# 2.0.0.beta1 - 2012-03-07
* Bugfix: #speak now correctly casts the argument to string if it is not SSML
View
11 lib/adhearsion/call_controller/ask.rb
@@ -52,7 +52,7 @@ module Ask
# @option options [Boolean] :interruptible If the prompt should be interruptible or not. Defaults to true
# @option options [String] :terminator Digit to terminate input
#
- # @return [Symbol] :failure on failure, :done if a match is reached and executed. Will only return if control is not passed.
+ # @return [Adhearsion::MenuDSL::Menu] a menu object on which #status may be called to establish the completion mode of the operation
#
# @raise [ArgumentError] Raised if no block is passed in
#
@@ -72,7 +72,7 @@ def ask(*args, &block)
else
logger.debug "Menu failed to get valid input. Calling \"failure\" hook."
menu_instance.execute_failure_hook
- return :failed
+ return menu_instance
end
case result_of_menu
@@ -89,7 +89,7 @@ def ask(*args, &block)
case result_of_menu
when MenuDSL::Menu::MenuGetAnotherDigitOrFinish
jump_to result_of_menu.match_object, :extension => result_of_menu.new_extension
- return true
+ return menu_instance
when MenuDSL::Menu::MenuGetAnotherDigitOrTimeout
logger.debug "Menu timed out. Calling \"timeout\" hook and restarting."
menu_instance.execute_timeout_hook
@@ -100,10 +100,11 @@ def ask(*args, &block)
when MenuDSL::Menu::MenuResultFound
logger.debug "Menu received valid input (#{result_of_menu.new_extension}). Calling the matching hook."
jump_to result_of_menu.match_object, :extension => result_of_menu.new_extension
- return true
+ return menu_instance
end # case
end # while
- return :done
+
+ menu_instance
end
alias :menu :ask
View
9 lib/adhearsion/menu_dsl/menu.rb
@@ -8,7 +8,7 @@ class Menu
DEFAULT_MAX_NUMBER_OF_TRIES = 1
DEFAULT_TIMEOUT = 5
- attr_reader :builder, :timeout, :tries_count, :max_number_of_tries, :terminator, :limit, :interruptible
+ attr_reader :builder, :timeout, :tries_count, :max_number_of_tries, :terminator, :limit, :interruptible, :status
def initialize(options = {}, &block)
@tries_count = 0 # Counts the number of tries the menu's been executed
@@ -35,6 +35,7 @@ def digit_buffer
def digit_buffer_string
digit_buffer.to_s
end
+ alias :result :digit_buffer_string
def digit_buffer_empty?
digit_buffer.empty?
@@ -92,26 +93,32 @@ def initialize_digit_buffer
end
def invalid!
+ @status = :invalid
MenuResultInvalid.new
end
def menu_result_found!(match_object, new_extension)
+ @status = :matched
MenuResultFound.new(match_object, new_extension)
end
def menu_terminated!
+ @status = :terminated
MenuTerminated.new
end
def menu_limit_reached!
+ @status = :limited
MenuLimitReached.new
end
def get_another_digit_or_finish!(match_payload, new_extension)
+ @status = :multi_matched
MenuGetAnotherDigitOrFinish.new(match_payload, new_extension)
end
def get_another_digit_or_timeout!
+ @status = :potential
MenuGetAnotherDigitOrTimeout.new
end
View
17 spec/adhearsion/call_controller/ask_spec.rb
@@ -57,7 +57,7 @@ class CallController
describe "#ask" do
let(:sound_files) { ["press", "button"] }
- let(:menu_instance) { flexmock MenuDSL::Menu.new }
+ let(:menu_instance) { MenuDSL::Menu.new }
let(:result_done) { MenuDSL::Menu::MenuResultDone.new }
let(:result_terminated) { MenuDSL::Menu::MenuTerminated.new }
@@ -68,6 +68,7 @@ class CallController
let(:result_found) { MenuDSL::Menu::MenuResultFound.new(:match_object, :new_extension) }
before(:each) do
+ flexmock menu_instance
flexmock(MenuDSL::Menu).should_receive(:new).and_return(menu_instance)
end
@@ -75,28 +76,28 @@ class CallController
menu_instance.should_receive(:should_continue?).and_return(true)
menu_instance.should_receive(:continue).and_return(result_done)
result = subject.ask(sound_files)
- result.should be == :done
+ result.should be menu_instance
end
it "exits the function if MenuTerminated" do
menu_instance.should_receive(:should_continue?).and_return(true)
menu_instance.should_receive(:continue).and_return(result_terminated)
result = subject.ask(sound_files)
- result.should be == :done
+ result.should be menu_instance
end
it "exits the function if MenuLimitReached" do
menu_instance.should_receive(:should_continue?).and_return(true)
menu_instance.should_receive(:continue).and_return(result_limit_reached)
result = subject.ask(sound_files)
- result.should be == :done
+ result.should be menu_instance
end
it "executes failure hook and returns :failure if menu fails" do
menu_instance.should_receive(:should_continue?).and_return(false)
menu_instance.should_receive(:execute_failure_hook)
result = subject.ask(sound_files)
- result.should be == :failed
+ result.should be menu_instance
end
it "executes invalid hook if input is invalid" do
@@ -104,7 +105,8 @@ class CallController
menu_instance.should_receive(:continue).and_return(result_invalid, result_done)
menu_instance.should_receive(:execute_invalid_hook)
menu_instance.should_receive(:restart!)
- subject.ask(sound_files)
+ result = subject.ask(sound_files)
+ result.should be menu_instance
end
it "plays audio, then executes timeout hook if input times out" do
@@ -136,7 +138,8 @@ class CallController
menu_instance.should_receive(:should_continue?).and_return(true)
menu_instance.should_receive(:continue).and_return(result_found)
subject.should_receive(:jump_to).with(:match_object, :extension => :new_extension)
- subject.ask(sound_files)
+ result = subject.ask(sound_files)
+ result.should be menu_instance
end
end#describe
View
18 spec/adhearsion/menu_dsl/menu_spec.rb
@@ -114,6 +114,7 @@ module MenuDSL
it "should add a digit to the buffer" do
subject << 'a'
subject.digit_buffer.should be == 'a'
+ subject.result.should be == 'a'
end
end
@@ -202,22 +203,19 @@ class MockControllerC; end
it "returns a MenuGetAnotherDigitOrTimeout if the digit buffer is empty" do
subject.continue.should be_a Menu::MenuGetAnotherDigitOrTimeout
+ menu_instance.status.should be nil
end
it "asks for another digit if it has potential matches" do
menu_instance << 2
menu_instance.continue.should be_a Menu::MenuGetAnotherDigitOrTimeout
+ menu_instance.status.should be == :potential
end
it "returns a MenuResultInvalid if there are no matches" do
menu_instance << 9
menu_instance.continue.should be_a Menu::MenuResultInvalid
- end
-
- it "returns a MenuGetAnotherDigitOrFinish if it has exact and potential matches" do
- menu_instance << 3
- menu_result = menu_instance.continue
- menu_result.should be_a Menu::MenuGetAnotherDigitOrFinish
+ menu_instance.status.should be == :invalid
end
it "returns the first exact match when it has exact and potentials" do
@@ -226,12 +224,14 @@ class MockControllerC; end
menu_result.should be_a Menu::MenuGetAnotherDigitOrFinish
menu_result.match_object.should be == MockControllerB
menu_result.new_extension.should be == "3"
+ menu_instance.status.should be == :multi_matched
end
it "returns a MenuResultFound if it has exact matches" do
menu_instance << 6
menu_result = menu_instance.continue
menu_result.should be_a Menu::MenuResultFound
+ menu_instance.status.should be == :matched
end
it "returns the first exact match when it has only exact matches" do
@@ -246,10 +246,11 @@ class MockControllerC; end
let(:options) { { :terminator => '#' } }
context "when the terminator is issued" do
- it "returns a MenuTerminated" do
+ it "returns a MenuTerminated and sets the status to :terminated" do
menu_instance << '#'
menu_instance.continue.should be_a Menu::MenuTerminated
menu_instance.continue.should be_a Menu::MenuResultDone
+ menu_instance.status.should be == :terminated
end
end
end
@@ -257,10 +258,11 @@ class MockControllerC; end
context "when a digit limit is set" do
let(:options) { { :limit => 1 } }
- it "it returns MenuLimitReached" do
+ it "it returns MenuLimitReached and sets the status to :limited" do
menu_instance << 2
menu_instance.continue.should be_a Menu::MenuLimitReached
menu_instance.continue.should be_a Menu::MenuResultDone
+ menu_instance.status.should be == :limited
end
end

No commit comments for this range

Something went wrong with that request. Please try again.