Class: SplitIoClient::CombiningMatcher
- Inherits:
-
Object
- Object
- SplitIoClient::CombiningMatcher
- Defined in:
- lib/splitclient-rb/engine/matchers/combining_matcher.rb
Overview
class to implement the combining matcher
Constant Summary collapse
- MATCHER_TYPE =
'COMBINING_MATCHER'.freeze
Instance Method Summary collapse
-
#equals?(obj) ⇒ Boolean
evaluates if the given object equals the matcher.
-
#eval_and(args) ⇒ boolean
auxiliary method to evaluate each of the matchers within the combiner.
-
#initialize(combiner = '', matchers = []) ⇒ CombiningMatcher
constructor
A new instance of CombiningMatcher.
-
#match?(args) ⇒ boolean
evaluates if the key matches the matchers within the combiner.
- #match_with_key?(matcher) ⇒ Boolean
-
#to_s ⇒ Object
function to print string value for this matcher.
Constructor Details
#initialize(combiner = '', matchers = []) ⇒ CombiningMatcher
Returns a new instance of CombiningMatcher.
8 9 10 11 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 8 def initialize(combiner = '', matchers = []) @combiner = combiner @matchers = matchers end |
Instance Method Details
#equals?(obj) ⇒ Boolean
evaluates if the given object equals the matcher
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 66 def equals?(obj) if obj.nil? false elsif !obj.instance_of?(CombiningMatcher) false elsif self.equal?(obj) true else false end end |
#eval_and(args) ⇒ boolean
auxiliary method to evaluate each of the matchers within the combiner
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 44 def eval_and(args) # Convert all keys to symbols args[:attributes] = args[:attributes].inject({}){ |memo, (k,v)| memo[k.to_sym] = v; memo } if args && args[:attributes] @matchers.all? do |matcher| if match_with_key?(matcher) matcher.match?(value: args[:matching_key]) else matcher.match?(args) end end end |
#match?(args) ⇒ boolean
evaluates if the key matches the matchers within the combiner
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 22 def match?(args) return false if @matchers.empty? case @combiner when Combiners::AND return eval_and(args) else @logger.error('Invalid combiner type') end false end |
#match_with_key?(matcher) ⇒ Boolean
56 57 58 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 56 def match_with_key?(matcher) matcher.respond_to?(:attribute) && matcher.attribute.nil? && matcher.string_type? end |
#to_s ⇒ Object
function to print string value for this matcher
82 83 84 |
# File 'lib/splitclient-rb/engine/matchers/combining_matcher.rb', line 82 def to_s @matcher_list.map(&:to_s).join("#{@combiner} ") end |