Sha256: e80d24fab92d12fe288c56b890e3cb2036e5b74e67a256a0cc42e0af9d2a2722
Contents?: true
Size: 1.5 KB
Versions: 19
Compression:
Stored size: 1.5 KB
Contents
require File.join(File.dirname(__FILE__), 'matchers.rb') module Adhearsion module VoIP class MenuBuilder def initialize @patterns = [] @menu_callbacks = {} end def method_missing(match_payload, *patterns, &block) name_string = match_payload.to_s if patterns.any? patterns.each do |pattern| @patterns << MatchCalculator.build_with_pattern(pattern, match_payload) end else raise ArgumentError, "You cannot call this method without patterns!" end nil end def weighted_match_calculators @patterns end def execute_hook_for(symbol, input) callback = @menu_callbacks[symbol] callback.call input if callback end def on_invalid(&block) raise LocalJumpError, "Must supply a block!" unless block_given? @menu_callbacks[:invalid] = block end def on_premature_timeout(&block) raise LocalJumpError, "Must supply a block!" unless block_given? @menu_callbacks[:premature_timeout] = block end def on_failure(&block) raise LocalJumpError, "Must supply a block!" unless block_given? @menu_callbacks[:failure] = block end def calculate_matches_for(result) returning CalculatedMatchCollection.new do |collection| weighted_match_calculators.each do |pattern| collection << pattern.match(result) end end end end end end
Version data entries
19 entries across 19 versions & 7 rubygems