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-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc18-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc18 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc17-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc17 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc16-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc16 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc15-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc15 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc14-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc14 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc13-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc13 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc12-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc12 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc11-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc11 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc10-java lib/splitclient-rb/engine/matchers/starts_with_matcher.rb
splitclient-rb-7.3.3.pre.rc10 lib/splitclient-rb/engine/matchers/starts_with_matcher.rb