Sha256: 9ce97620467d6002e0bd860f68c3e2e4754b1338e7161234d93d97305b7a6957

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

module SplitIoClient

  #
  # class to implement the user defined matcher
  #
  class UserDefinedSegmentMatcher < NoMethodError

    attr_reader :matcher_type

    @segment = nil

    def initialize(segment)
      @matcher_type = "IN_SEGMENT"
      unless segment.nil?
        @segment = segment
      end
    end

    #
    # evaluates if the key matches the matcher
    #
    # @param key [string] key value to be matched
    #
    # @return [boolean] evaluation of the key against the segment
    def match?(key)
      matches = false
      unless @segment.users.nil?
        matches = @segment.users.include?(key)
      end
      matches
    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?(UserDefinedSegmentMatcher)
        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
      'in segment ' + @segment.name
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
splitclient-rb-1.0.3 lib/splitclient-engine/matchers/user_defined_segment_matcher.rb
splitclient-rb-1.0.3.wip2 lib/splitclient-engine/matchers/user_defined_segment_matcher.rb
splitclient-rb-1.0.3.wip1 lib/splitclient-engine/matchers/user_defined_segment_matcher.rb
splitclient-rb-1.0.2 lib/splitclient-engine/matchers/user_defined_segment_matcher.rb
splitclient-rb-1.0.2.wip2 lib/splitclient-engine/matchers/user_defined_segment_matcher.rb
splitclient-rb-1.0.2.wip lib/splitclient-engine/matchers/user_defined_segment_matcher.rb