Sha256: 41793ea91fe69f36d7948879ba194428d192853909ddbf3954541a0588ffd0aa

Contents?: true

Size: 1.31 KB

Versions: 41

Compression:

Stored size: 1.31 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 = {})
      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 <= @before && @after <= request.timestamp
        return request
      elsif @after && @before.nil? && @after <= request.timestamp
        return request
      elsif @before && @after.nil? && request.timestamp <= @before 
        return request
      end

      return nil
    end 
  end
  
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
wvanbergen-request-log-analyzer-1.3.6 lib/request_log_analyzer/filter/timespan.rb
wvanbergen-request-log-analyzer-1.3.7 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.7 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.6 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.5 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.4 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.3 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.2 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.1 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.3.0 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.2.9 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.2.8 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.2.7 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.2.6 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.2.3 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.2.1 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.2.0 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.1.6 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.1.4 lib/request_log_analyzer/filter/timespan.rb
request-log-analyzer-1.1.3 lib/request_log_analyzer/filter/timespan.rb