Sha256: 2b1edee1b2fd8487e4c1da1b2a47abb76a8aff6edea237c4cd15d2b6697f5a02

Contents?: true

Size: 1.06 KB

Versions: 294

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  class ContainsMatcher
    MATCHER_TYPE = 'CONTAINS_WITH'

    attr_reader :attribute

    def initialize(attribute, substr_list, logger, validator)
      @attribute = attribute
      @substr_list = substr_list
      @logger = logger
      @validator = validator
    end

    def match?(args)
      @logger.log_if_debug('[ContainsMatcher] evaluating value and attributes.')

      return false unless @validator.valid_matcher_arguments(args)

      value = get_value(args)

      @logger.log_if_debug("[ContainsMatcher] Value from parameters: #{value}.")
      return false if @substr_list.empty?

      matches = @substr_list.any? { |substr| value.to_s.include? substr }
      @logger.log_if_debug("[ContainsMatcher] #{@value} contains any of #{@substr_list} -> #{matches} .")
      matches
    end

    def string_type?
      true
    end

    private

    def get_value(args)
      args[:value] || args[:attributes].fetch(@attribute) do |a|
        args[:attributes][a.to_s] || args[:attributes][a.to_sym]
      end
    end
  end
end

Version data entries

294 entries across 294 versions & 1 rubygems

Version Path
splitclient-rb-8.1.1.pre.rc2-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.1.1.pre.rc2 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.1.1.pre.rc1-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.1.1.pre.rc1 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.1.0-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.1.0 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.1.0.pre.rc1-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.1.0.pre.rc1 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.1-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.1 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.1.pre.rc1-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.1.pre.rc1 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.0-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.0 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.0.pre.rc2-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.0.pre.rc2 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.0.pre.rc1-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-8.0.0.pre.rc1 lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-7.3.5.pre.rc5-java lib/splitclient-rb/engine/matchers/contains_matcher.rb
splitclient-rb-7.3.5.pre.rc5 lib/splitclient-rb/engine/matchers/contains_matcher.rb