Sha256: d35fa188717c1a87276caa2f36f6b7f4c7b2293b9048e2d9d1a257e3df74e58f

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module SplitIoClient

  class BetweenMatcher < NoMethodError

    attr_reader :matcher_type

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

    def match?(attributes)
      matches = false
      if (!attributes.nil? && attributes.key?(@attribute.to_sym))
        param_value = get_formatted_value(attributes[@attribute.to_sym])
        matches = ((param_value >= @start_value) && (param_value <= @end_value))
      end
    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)
      case @data_type
        when "NUMBER"
          return value
        when "DATETIME"
          return ::Utilities.to_milis_zero_out_from_seconds value
        else
          @logger.error('Invalid data type')
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
splitclient-rb-1.0.3.wip1 lib/splitclient-engine/matchers/between_matcher.rb
splitclient-rb-1.0.2 lib/splitclient-engine/matchers/between_matcher.rb
splitclient-rb-1.0.2.wip2 lib/splitclient-engine/matchers/between_matcher.rb
splitclient-rb-1.0.2.wip lib/splitclient-engine/matchers/between_matcher.rb