class RequestLogAnalyzer::Filter::Field
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.
Attributes
field[R]
mode[R]
value[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/field.rb 10 def initialize(file_format, options = {}) 11 super(file_format, options) 12 setup_filter 13 end
Public Instance Methods
filter(request)
click to toggle source
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
# File lib/request_log_analyzer/filter/field.rb 32 def filter(request) 33 found_field = request.every(@field).any? { |value| @value === value.to_s } 34 return nil if !found_field && @mode == :select 35 return nil if found_field && @mode == :reject 36 request 37 end
setup_filter()
click to toggle source
Setup mode, field and value.
# File lib/request_log_analyzer/filter/field.rb 16 def setup_filter 17 @mode = (@options[:mode] || :accept).to_sym 18 @field = @options[:field].to_sym 19 20 # Convert the timestamp to the correct formats for quick timestamp comparisons 21 if @options[:value].is_a?(String) && @options[:value][0, 1] == '/' && @options[:value][-1, 1] == '/' 22 @value = Regexp.new(@options[:value][1..-2]) 23 else 24 @value = @options[:value] # TODO: convert value? 25 end 26 end