Sha256: e7312217f0ee1d94fa144c7691054c2f761d11075444e7107e4f686ea492d7db

Contents?: true

Size: 1.27 KB

Versions: 300

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  class LessThanOrEqualToMatcher < Matcher
    MATCHER_TYPE = 'LESS_THAN_OR_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('[LessThanOrEqualToMatcher] 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("[LessThanOrEqualToMatcher] #{value} less than or equal 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 # sdk returns already miliseconds, turning to seconds to do a correct zero_hour
        SplitIoClient::Utilities.to_milis_zero_out_from_seconds(value)
      else
        @logger.error('Invalid data type')
      end
    end
  end
end

Version data entries

300 entries across 300 versions & 1 rubygems

Version Path
splitclient-rb-7.0.1.pre.rc7-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc7 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc6-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc6 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc5-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc5 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc4-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc4 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc3-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc3 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc1-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.1.pre.rc1 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0.pre.rc3-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0.pre.rc3 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0.pre.rc2-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0.pre.rc2 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0.pre.rc1-java lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb
splitclient-rb-7.0.0.pre.rc1 lib/splitclient-rb/engine/matchers/less_than_or_equal_to_matcher.rb