Sha256: ae52ac569acc4c990c379a698ae3011f2ef6be13a5c6dc3d406b4390d101e59d

Contents?: true

Size: 1.1 KB

Versions: 28

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  class EqualToMatcher < Matcher
    MATCHER_TYPE = 'EQUAL_TO'

    attr_reader :attribute

    def initialize(attribute_hash)
      @attribute = attribute_hash[:attribute]
      @data_type = attribute_hash[:data_type]
      @value = formatted_value(attribute_hash[:value], true)
    end

    def match?(args)
      SplitLogger.log_if_debug('[EqualsToMatcher] evaluating value and attributes.')

      return false unless SplitIoClient::Validators.valid_matcher_arguments(args)

      value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])

      matches = value.is_a?(Integer) ? (value == @value) : false
      SplitLogger.log_if_debug("[EqualsToMatcher] #{value} equals to #{@value} -> #{matches}")
      matches
    end

    private

    def formatted_value(value, sdk_data = false)
      case @data_type
      when 'NUMBER'
        value
      when 'DATETIME'
        value /= 1000 if sdk_data

        SplitIoClient::Utilities.to_milis_zero_out_from_hour value
      else
        @logger.error('Invalid data type')
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
splitclient-rb-6.4.1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.1.pre.rc3-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.1.pre.rc3 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.1.pre.rc2-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.1.pre.rc2 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.1.pre.rc1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.1.pre.rc1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.0-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.0 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.0.pre.rc1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.4.0.pre.rc1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.3.0-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.3.0 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.3.0.pre.rc1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.3.0.pre.rc1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.2.0-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.2.0 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.2.0.pre.rc2-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-6.2.0.pre.rc2 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb