Sha256: f768a20a9efa2859e1861c92f3a453376625b9c5d4bfa37e51e81496d71858cd

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

module Adhearsion
  module MenuDSL
    class CalculatedMatch

      def self.failed_match!(pattern, query, match_payload)
        new :pattern => pattern, :query => query, :match_payload => match_payload
      end

      attr_reader :match_payload, :potential_matches, :exact_matches, :pattern, :query, :block

      def initialize(options = {})
        @pattern, @query, @match_payload, @block = options.values_at :pattern, :query, :match_payload, :block
        @potential_matches  = options[:potential_matches] ? Array(options[:potential_matches]) : []
        @exact_matches      = options[:exact_matches] ? Array(options[:exact_matches]) : []
      end

      def exact_match?
        exact_matches.any?
      end

      def potential_match?
        potential_matches.any?
      end

      def failed_match?
        !(potential_match? || exact_match?)
      end

      def type_of_match
        if exact_match?
          :exact
        elsif potential_match?
          :potential
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
adhearsion-2.0.0.beta1 lib/adhearsion/menu_dsl/calculated_match.rb
adhearsion-2.0.0.alpha3 lib/adhearsion/menu_dsl/calculated_match.rb
adhearsion-2.0.0.alpha2 lib/adhearsion/menu_dsl/calculated_match.rb
adhearsion-2.0.0.alpha1 lib/adhearsion/menu_dsl/calculated_match.rb