Sha256: b6940062726b57b42ae70a8f4daff7cb68bcfdf4bcdbfb1b62b0b1413041097e

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module SplitIoClient

  class EqualToMatcher < NoMethodError

    attr_reader :matcher_type

    def initialize(attribute_hash)
      @matcher_type = "EQUAL_TO"
      @attribute = attribute_hash[:attribute]
      @data_type = attribute_hash[:data_type]
      @value = get_formatted_value attribute_hash[:value], true
    end

    def match?(_matching_key, _bucketing_key, _evaluator, attributes)
      matches = false
      if (!attributes.nil? && attributes.key?(@attribute.to_sym))
        param_value = get_formatted_value(attributes[@attribute.to_sym])
        matches = param_value.is_a?(Integer) ? (param_value == @value) : false
      end
    end

    def equals?(obj)
      if obj.nil?
        false
      elsif !obj.instance_of?(EqualToMatcher)
        false
      elsif self.equal?(obj)
        true
      else
        false
      end
    end

    private
    def get_formatted_value(value, is_sdk_data = false)
      case @data_type
        when "NUMBER"
          return value
        when "DATETIME"
          value = value/1000 if is_sdk_data
          return SplitIoClient::Utilities.to_milis_zero_out_from_hour value
        else
          @logger.error('Invalid data type')
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
splitclient-rb-4.2.2 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-4.2.1 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb
splitclient-rb-4.2.0 lib/splitclient-rb/engine/matchers/equal_to_matcher.rb