Sha256: de90f43c8784e8d53356da8a7612de27eb734d4f9ad8e09d4c6b9c70df19cb83

Contents?: true

Size: 1.14 KB

Versions: 294

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  class EqualToMatcher < Matcher
    MATCHER_TYPE = 'EQUAL_TO'

    attr_reader :attribute

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

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

      return false unless @validator.valid_matcher_arguments(args)

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

      matches = value.is_a?(Integer) ? (value == @value) : false
      @logger.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

294 entries across 294 versions & 1 rubygems

Version Path
splitclient-rb-8.3.0.pre.rc1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.3.0.pre.rc1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.2.0-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.2.0 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc4-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc4 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc3-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc3 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc2-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc2 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.3.pre.rc1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.2-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.2 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.2.pre.rc1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.2.pre.rc1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.1-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.1.pre.rc3-java lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-8.1.1.pre.rc3 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb