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

Version Path
eric-adhearsion-0.7.999 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
eric-adhearsion-0.8.0 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
jicksta-adhearsion-0.7.999 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
jicksta-adhearsion-0.8.0 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
jicksta-adhearsion-0.8.2 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
jicksta-adhearsion-0.8.3 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
kenwiesner-adhearsioncw-0.8.3 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
mtrudel-adhearsion-0.8.3 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
sant0sk1-adhearsion-0.7.999 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
sevenscale-adhearsion-0.7.1000 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
sevenscale-adhearsion-0.7.1003 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
sevenscale-adhearsion-0.8.0 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-0.8.6 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-0.8.5 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-0.8.4 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-0.8.3 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-0.8.0 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-0.8.2 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-0.8.1 lib/adhearsion/voip/menu_state_machine/menu_builder.rb