Class: RequestLogAnalyzer::Filter::Timespan

Inherits:
Base
  • Object
show all
Defined in:
lib/request_log_analyzer/filter/timespan.rb

Overview

Reject all requests not in given timespan Options

  • :after Only keep requests after this DateTime.

  • :before Only keep requests before this DateTime.

Instance Attribute Summary collapse

Attributes inherited from Base

#file_format, #options

Instance Method Summary collapse

Constructor Details

#initialize(file_format, options = {}) ⇒ Timespan

Returns a new instance of Timespan.



11
12
13
14
# File 'lib/request_log_analyzer/filter/timespan.rb', line 11

def initialize(file_format, options = {})
  super(file_format, options)
  setup_filter
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



9
10
11
# File 'lib/request_log_analyzer/filter/timespan.rb', line 9

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



9
10
11
# File 'lib/request_log_analyzer/filter/timespan.rb', line 9

def before
  @before
end

Instance Method Details

#filter(request) ⇒ Object

Returns request if:

* @after <= request.timestamp <= @before
* @after <= request.timestamp
* request.timestamp <= @before

Returns nil otherwise request Request object.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/request_log_analyzer/filter/timespan.rb', line 30

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

#setup_filterObject

Convert the timestamp to the correct formats for quick timestamp comparisons. These are stored in the before and after attr_reader fields.



19
20
21
22
# File 'lib/request_log_analyzer/filter/timespan.rb', line 19

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