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-8.5.0-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.5.0 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.5.0.pre.rc1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.5.0.pre.rc1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.1.pre.rc1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.1.pre.rc1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.0-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.0 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.0.pre.rc1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.0.pre.rc1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.0.rc.1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.4.0.rc.1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.2.pre.rc2-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.2.pre.rc2 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.2.pre.rc1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.2.pre.rc1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.1.pre.rc1-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-8.3.1.pre.rc1 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb