Sha256: 0504ebd2754f7013c5ab11e6a8f5cecdb37393feed893493f4c61203b94b01e8
Contents?: true
Size: 1.9 KB
Versions: 9
Compression:
Stored size: 1.9 KB
Contents
require 'splitclient-engine/matchers/combiners' module SplitIoClient # # class to implement the combining matcher # class CombiningMatcher < NoMethodError # # list of matcher within the combiner # @matcher_list = [] # # combiner value # @combiner = '' def initialize(combiner, delegates) unless delegates.nil? @matcher_list = delegates end unless combiner.nil? @combiner = combiner end end # # evaluates if the key matches the matchers within the combiner # # @param key [string] key value to be matched # # @return [boolean] match value for combiner delegates def match?(key) if @matcher_list.empty? return false end case @combiner when Combiners::AND return and_eval(key) else #throws error end end # # auxiliary method to evaluate each of the matchers within the combiner # # @param key [string] key value to be matched # # @return [boolean] match value for combiner delegates def and_eval(key) result = true @matcher_list.each do |delegate| result &= (delegate.match?(key)) end result 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?(CombiningMatcher) 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 result = '' @matcher_list.each_with_index do |matcher, i| result += matcher.to_s result += ' ' + @combiner if i != 0 end result end end end
Version data entries
9 entries across 9 versions & 1 rubygems