Class: RequestLogAnalyzer::Filter::Field
- Defined in:
- lib/request_log_analyzer/filter/field.rb
Overview
Filter to select or reject a specific field Options
-
:mode
:reject or :accept. -
:field
Specific field to accept or reject. -
:value
Value that the field should match to be accepted or rejected.
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Base
Instance Method Summary collapse
-
#filter(request) ⇒ Object
Keep request if @mode == :select and request has the field and value.
-
#initialize(file_format, options = {}) ⇒ Field
constructor
A new instance of Field.
-
#setup_filter ⇒ Object
Setup mode, field and value.
Constructor Details
#initialize(file_format, options = {}) ⇒ Field
Returns a new instance of Field.
12 13 14 15 |
# File 'lib/request_log_analyzer/filter/field.rb', line 12 def initialize(file_format, = {}) super(file_format, ) setup_filter end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
10 11 12 |
# File 'lib/request_log_analyzer/filter/field.rb', line 10 def field @field end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
10 11 12 |
# File 'lib/request_log_analyzer/filter/field.rb', line 10 def mode @mode end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/request_log_analyzer/filter/field.rb', line 10 def value @value end |
Instance Method Details
#filter(request) ⇒ Object
Keep request if @mode == :select and request has the field and value. Drop request if @mode == :reject and request has the field and value. Returns nil otherwise. request
Request Object
34 35 36 37 38 39 |
# File 'lib/request_log_analyzer/filter/field.rb', line 34 def filter(request) found_field = request.every(@field).any? { |value| @value === value.to_s } return nil if !found_field && @mode == :select return nil if found_field && @mode == :reject return request end |
#setup_filter ⇒ Object
Setup mode, field and value.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/request_log_analyzer/filter/field.rb', line 18 def setup_filter @mode = (@options[:mode] || :accept).to_sym @field = @options[:field].to_sym # Convert the timestamp to the correct formats for quick timestamp comparisons if @options[:value].kind_of?(String) && @options[:value][0, 1] == '/' && @options[:value][-1, 1] == '/' @value = Regexp.new(@options[:value][1..-2]) else @value = @options[:value] # TODO: convert value? end end |