Sha256: 728a357b635a40bdb8f2eb5357c17ae279d14e5c44defc9f3403a463c6601edd

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

module SplitIoClient

  #
  # class to implement the negation of a matcher
  #
  class NegationMatcher < NoMethodError

    @matcher = nil

    def initialize(matcher)
      unless matcher.nil?
        @matcher = matcher
      end
    end

    #
    # evaluates if the key matches the negation of the matcher
    #
    # @param key [string] key value to be matched
    #
    # @return [boolean] evaluation of the negation matcher
    def match?(matching_key, bucketing_key, evaluator, attributes)
      !@matcher.match?(matching_key, bucketing_key, evaluator, attributes)
    end

    #
    # evaluates if the given object equals the matcher
    #
    # @param obj [object] object to be evaluated
    #
    # @returns [boolean] true if obj equals the matcher
    def equals?(obj)
      if obj.nil?
        false
      elsif !obj.instance_of?(NegationMatcher)
        false
      elsif self.equal?(obj)
        true
      else
        false
      end
    end

    #
    # function to print string value for this matcher
    #
    # @reutrn [string] string value of this matcher
    def to_s
      'not ' + @matcher.to_s
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
splitclient-rb-4.3.0.canary.2 lib/splitclient-rb/engine/matchers/negation_matcher.rb
splitclient-rb-4.3.0.canary.1 lib/splitclient-rb/engine/matchers/negation_matcher.rb
splitclient-rb-4.2.2 lib/splitclient-rb/engine/matchers/negation_matcher.rb
splitclient-rb-4.2.1 lib/splitclient-rb/engine/matchers/negation_matcher.rb
splitclient-rb-4.2.0 lib/splitclient-rb/engine/matchers/negation_matcher.rb