Sha256: 34a73a83cbecb1c94ded8d0dcccd1dc579a759b87919bf3d03e27cb50fe2e10c

Contents?: true

Size: 1.38 KB

Versions: 15

Compression:

Stored size: 1.38 KB

Contents

module RequestLogAnalyzer::Filter

  # Reject all requests not in given timespan
  # Options
  # * <tt>:after</tt> Only keep requests after this DateTime.
  # * <tt>:before</tt> Only keep requests before this DateTime.
  class Timespan < Base

    attr_reader :before, :after

    def initialize(file_format, options = {})
      @after  = nil
      @before = nil
      super(file_format, options)
      setup_filter
    end


    # Convert the timestamp to the correct formats for quick timestamp comparisons.
    # These are stored in the before and after attr_reader fields.
    def setup_filter
      @after  = @options[:after].strftime('%Y%m%d%H%M%S').to_i  if options[:after]
      @before = @options[:before].strftime('%Y%m%d%H%M%S').to_i if options[:before]
    end

    # Returns request if:
    #   * @after <= request.timestamp <= @before
    #   * @after <= request.timestamp
    #   * request.timestamp <= @before
    # Returns nil otherwise
    # <tt>request</tt> Request object.
    def filter(request)
      if @after && @before && request.timestamp && request.timestamp <= @before && @after <= request.timestamp
        return request
      elsif @after && @before.nil? && request.timestamp && @after <= request.timestamp
        return request
      elsif @before && @after.nil? && request.timestamp && request.timestamp <= @before
        return request
      end

      return nil
    end
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
request-log-analyzer-1.13.1 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.13.0 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.11 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.10 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.9 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.8 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.7 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.6 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.5 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.4 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.3 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.2 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.1 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.12.0 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.11.1 lib/request_log_analyzer/filter/timespan.rb