class RequestLogAnalyzer::Filter::Timespan
Reject all requests not in given timespan Options
-
:after
Only keep requests after this DateTime. -
:before
Only keep requests before this DateTime.
Attributes
after[R]
before[R]
Public Class Methods
new(file_format, options = {})
click to toggle source
Calls superclass method
RequestLogAnalyzer::Filter::Base::new
# File lib/request_log_analyzer/filter/timespan.rb 9 def initialize(file_format, options = {}) 10 @after = nil 11 @before = nil 12 super(file_format, options) 13 setup_filter 14 end
Public Instance Methods
filter(request)
click to toggle source
Returns request if:
* @after <= request.timestamp <= @before * @after <= request.timestamp * request.timestamp <= @before
Returns nil otherwise request
Request
object.
# File lib/request_log_analyzer/filter/timespan.rb 29 def filter(request) 30 if @after && @before && request.timestamp && request.timestamp <= @before && @after <= request.timestamp 31 return request 32 elsif @after && @before.nil? && request.timestamp && @after <= request.timestamp 33 return request 34 elsif @before && @after.nil? && request.timestamp && request.timestamp <= @before 35 return request 36 end 37 38 nil 39 end
setup_filter()
click to toggle source
Convert the timestamp to the correct formats for quick timestamp comparisons. These are stored in the before and after attr_reader fields.
# File lib/request_log_analyzer/filter/timespan.rb 18 def setup_filter 19 @after = @options[:after].strftime('%Y%m%d%H%M%S').to_i if options[:after] 20 @before = @options[:before].strftime('%Y%m%d%H%M%S').to_i if options[:before] 21 end