Class: RequestLogAnalyzer::Filter::Timespan
- 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
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
Attributes inherited from Base
Instance Method Summary collapse
-
#filter(request) ⇒ Object
Returns request if: * @after <= request.timestamp <= @before * @after <= request.timestamp * request.timestamp <= @before Returns nil otherwise
request
Request object. -
#initialize(file_format, options = {}) ⇒ Timespan
constructor
A new instance of Timespan.
-
#setup_filter ⇒ Object
Convert the timestamp to the correct formats for quick timestamp comparisons.
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, = {}) super(file_format, ) setup_filter end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
9 10 11 |
# File 'lib/request_log_analyzer/filter/timespan.rb', line 9 def after @after end |
#before ⇒ Object (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. <= @before && @after <= request. return request elsif @after && @before.nil? && @after <= request. return request elsif @before && @after.nil? && request. <= @before return request end return nil end |
#setup_filter ⇒ Object
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 [:after] @before = @options[:before].strftime('%Y%m%d%H%M%S').to_i if [:before] end |