class Adhearsion::CallController::MenuDSL::Menu

Constants

DEFAULT_MAX_NUMBER_OF_TRIES
DEFAULT_TIMEOUT
InvalidStructureError

The superclass from which all message-like exceptions descend. It should never be instantiated directly.

Attributes

builder[R]
interruptible[R]
limit[R]
max_number_of_tries[R]
renderer[R]
status[R]
terminator[R]
timeout[R]
tries_count[R]

Public Class Methods

new(options = {}, &block) click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 16
def initialize(options = {}, &block)
  @tries_count          = 0 # Counts the number of tries the menu's been executed
  @timeout              = options[:timeout] || DEFAULT_TIMEOUT
  @max_number_of_tries  = options[:tries]   || DEFAULT_MAX_NUMBER_OF_TRIES
  @terminator           = options[:terminator].to_s
  @limit                = options[:limit]
  @interruptible        = options.has_key?(:interruptible) ? options[:interruptible] : true
  @builder              = MenuDSL::MenuBuilder.new
  @terminated           = false
  @renderer             = options[:renderer]

  @builder.build(&block) if block

  initialize_digit_buffer
end

Public Instance Methods

<<(other) click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 41
def <<(other)
  if other == terminator
    @terminated = true
  else
    digit_buffer << other
  end
end
continue() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 62
def continue
  return get_another_digit_or_timeout! if digit_buffer_empty?

  return menu_terminated! if @terminated
  return menu_validator_terminated! if execute_validator_hook
  return menu_limit_reached! if limit && digit_buffer.size >= limit

  calculated_matches = builder.calculate_matches_for digit_buffer_string

  if calculated_matches.exact_match_count >= 1
    first_exact_match = calculated_matches.exact_matches.first
    if calculated_matches.potential_match_count.zero?
      menu_result_found! first_exact_match, digit_buffer_string
    else
      get_another_digit_or_finish! first_exact_match.match_payload, first_exact_match.query
    end
  elsif calculated_matches.potential_match_count >= 1 || !@builder.has_matchers?
    get_another_digit_or_timeout!
  else
    invalid!
  end
end
digit_buffer() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 49
def digit_buffer
  @digit_buffer
end
digit_buffer_empty?() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 58
def digit_buffer_empty?
  digit_buffer.empty?
end
digit_buffer_string() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 53
def digit_buffer_string
  digit_buffer.to_s
end
Also aliased as: result
execute_failure_hook() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 106
def execute_failure_hook
  builder.execute_hook_for :failure, digit_buffer_string
end
execute_invalid_hook() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 98
def execute_invalid_hook
  builder.execute_hook_for :invalid, digit_buffer_string
end
execute_timeout_hook() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 102
def execute_timeout_hook
  builder.execute_hook_for :timeout, digit_buffer_string
end
execute_validator_hook() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 110
def execute_validator_hook
  builder.execute_hook_for :validator, digit_buffer_string
end
restart!() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 89
def restart!
  @tries_count += 1
  digit_buffer.clear!
end
result()
Alias for: digit_buffer_string
should_continue?() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 85
def should_continue?
  tries_count < max_number_of_tries
end
timeout!() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 94
def timeout!
  @status = :timeout
end
validate(mode = nil) click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 32
def validate(mode = nil)
  case mode
  when :basic
    @terminator.present? || !!@limit || raise(InvalidStructureError, "You must specify at least one of limit or terminator")
  else
    @builder.has_matchers? || raise(InvalidStructureError, "You must specify one or more matchers")
  end
end

Protected Instance Methods

get_another_digit_or_finish!(match_payload, new_extension) click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 147
def get_another_digit_or_finish!(match_payload, new_extension)
  @status = :multi_matched
  MenuGetAnotherDigitOrFinish.new(match_payload, new_extension)
end
get_another_digit_or_timeout!() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 152
def get_another_digit_or_timeout!
  @status = :potential
  MenuGetAnotherDigitOrTimeout.new
end
initialize_digit_buffer() click to toggle source

If you're using a more complex class in subclasses, you may want to override this method in addition to the digit buffer, digit_buffer_empty, and digit_buffer_string methods

# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 118
def initialize_digit_buffer
  @digit_buffer = ClearableStringBuffer.new
end
invalid!() click to toggle source
# File lib/adhearsion/call_controller/menu_dsl/menu.rb, line 122
def invalid!
  @status = :invalid
  MenuResultInvalid.new
end
menu_limit_reached!() click to toggle source
menu_result_found!(match_object, new_extension) click to toggle source
menu_terminated!() click to toggle source
menu_validator_terminated!() click to toggle source