Sha256: b6ac6a47507164019ffdaa6396f6b052977d7a218db2b3649d89be011dec0c1e

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 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)
        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)
        CalculatedMatchCollection.new.tap do |collection|
          weighted_match_calculators.each do |pattern|
            collection << pattern.match(result)
          end
        end
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
adhearsion-1.2.6 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.2.5 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.2.4 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.2.3 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.2.1 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.2.0 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.1.1 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.1.0 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.0.3 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.0.2 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-cw-1.0.2.3 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-cw-1.0.2.2 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-cw-1.0.2.1 lib/adhearsion/voip/menu_state_machine/menu_builder.rb
adhearsion-1.0.1 lib/adhearsion/voip/menu_state_machine/menu_builder.rb