lib/request_log_analyzer/tracker/duration.rb in wvanbergen-request-log-analyzer-1.3.1 vs lib/request_log_analyzer/tracker/duration.rb in wvanbergen-request-log-analyzer-1.3.2

- old
+ new

@@ -26,11 +26,13 @@ # Check if duration and catagory option have been received, def prepare raise "No duration field set up for category tracker #{self.inspect}" unless options[:duration] raise "No categorizer set up for duration tracker #{self.inspect}" unless options[:category] - + + @categorizer = options[:category].respond_to?(:call) ? options[:category] : lambda { |request| request[options[:category]] } + @durationizer = options[:duration].respond_to?(:call) ? options[:duration] : lambda { |request| request[options[:duration]] } @categories = {} end # Get the duration information fron the request and store it in the different categories. # <tt>request</tt> The request. @@ -47,18 +49,18 @@ end else raise "Capture mismatch for multiple values in a request" end else - category = options[:category].respond_to?(:call) ? options[:category].call(request) : request[options[:category]] - duration = options[:duration].respond_to?(:call) ? options[:duration].call(request) : request[options[:duration]] + category = @categorizer.call(request) # options[:category].respond_to?(:call) ? options[:category].call(request) : request[options[:category]] + duration = @durationizer.call(request) # options[:duration].respond_to?(:call) ? options[:duration].call(request) : request[options[:duration]] if duration.kind_of?(Float) && category.kind_of?(String) @categories[category] ||= {:hits => 0, :cumulative => 0.0, :min => duration, :max => duration } @categories[category][:hits] += 1 @categories[category][:cumulative] += duration @categories[category][:min] = duration if duration < @categories[category][:min] - @categories[category][:max] = duration if duration > @categories[category][:max] + @categories[category][:max] = duration if duration > @categories[category][:max] end end end # Get the number of hits of a specific category.