Sha256: fd9b86e64cf26aa9f98c3f62d901325103aebcab2ce19212c52af7791c8ea460

Contents?: true

Size: 1.28 KB

Versions: 39

Compression:

Stored size: 1.28 KB

Contents

module SplitIoClient

  class BetweenMatcher < NoMethodError

    attr_reader :matcher_type

    def initialize(attribute_hash)
      @matcher_type = "BETWEEN"
      @attribute = attribute_hash[:attribute]
      @data_type = attribute_hash[:data_type]
      @start_value = get_formatted_value attribute_hash[:start_value], true
      @end_value = get_formatted_value attribute_hash[:end_value], true
    end

    def match?(key, 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 >= @start_value) && (param_value <= @end_value)) : false
      end

      matches
    end

    def equals?(obj)
      if obj.nil?
        false
      elsif !obj.instance_of?(BetweenMatcher)
        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 ::Utilities.to_milis_zero_out_from_seconds value
        else
          @logger.error('Invalid data type')
      end
    end
  end

end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
splitclient-rb-4.1.0 lib/engine/matchers/between_matcher.rb
splitclient-rb-4.1.0.pre.rc2 lib/engine/matchers/between_matcher.rb
splitclient-rb-4.1.0.pre.rc1 lib/engine/matchers/between_matcher.rb
splitclient-rb-4.0.0 lib/engine/matchers/between_matcher.rb
splitclient-rb-4.0.0.pre.rc1 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.3.0 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.3.0.pre.rc1 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.4 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.4.pre.rc5 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.4.pre.rc4 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.4.pre.rc3 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.4.pre.rc2 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.4.pre.rc1 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.3 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.3.pre.rc1 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.2 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.1 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.2.0 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.1.3 lib/engine/matchers/between_matcher.rb
splitclient-rb-3.1.3.pre.rc3 lib/engine/matchers/between_matcher.rb