Sha256: ee334e3ceb41b798ee9a637dde25fd8a4be5d4a0a9a9346ed164f89e262b1d56

Contents?: true

Size: 912 Bytes

Versions: 300

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

module SplitIoClient
  class StartsWithMatcher
    MATCHER_TYPE = 'STARTS_WITH'

    attr_reader :attribute

    def initialize(attribute, prefix_list, logger)
      @attribute = attribute
      @prefix_list = prefix_list
      @logger = logger
    end

    def match?(args)
      if @prefix_list.empty?
        @logger.log_if_debug('[StartsWithMatcher] Prefix List is empty.')
        return false
      end

      value = get_value(args)

      matches = @prefix_list.any? { |prefix| value.to_s.start_with? prefix }
      @logger.log_if_debug("[StartsWithMatcher] #{value} matches any of #{@prefix_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

300 entries across 300 versions & 1 rubygems

Version Path
splitclient-rb-7.3.3.pre.rc9-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc9 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc8-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc8 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc7-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc7 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc6-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc6 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc5-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc5 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc4-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc4 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc3-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc3 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc2-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc2 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.2-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.2 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb