lib/request_log_analyzer/request.rb in wvanbergen-request-log-analyzer-1.0.1 vs lib/request_log_analyzer/request.rb in wvanbergen-request-log-analyzer-1.0.2
- old
+ new
@@ -2,16 +2,10 @@
# The Request class represents a parsed request from the log file.
# Instances are created by the LogParser and are passed to the different aggregators, so they
# can do their aggregating work.
#
- # Note that RequestLogAnalyzer can run in two modes:
- # - Single line mode: every parsed line is regarded as a request. Request::single_line? will
- # return true in this case
- # - Combined requests mode: lines that belong together are grouped into one request.
- # Request#combined? will return true in this case.
- #
# This class provides several methods to access the data that was parsed from the log files.
# Request#first(field_name) returns the first (only) value corresponding to the given field
# Request#every(field_name) returns all values corresponding to the given field name as array.
class Request
@@ -52,11 +46,11 @@
alias :=~ :has_line_type?
# Returns the value that was captured for the "field" of this request.
# This function will return the first value that was captured if the field
- # was captured in multiple lines for a combined request.
+ # was captured in multiple lines
def first(field)
@attributes[field]
end
alias :[] :first
@@ -70,46 +64,32 @@
# during parsing. An empty request should never be sent to the aggregators
def empty?
@lines.length == 0
end
- # Checks whether this request contains exactly one line. This means that RequestLogAnalyzer
- # is running in single_line mode.
- def single_line?
- @lines.length == 1
- end
-
- # Checks whether this request contains more than one line. This means that RequestLogAnalyzer
- # is runring in combined requests mode.
- def combined?
- @lines.length > 1
- end
-
# Checks whether this request is completed. A completed request contains both a parsed header
# line and a parsed footer line. Not that calling this function in single line mode will always
# return false.
def completed?
- puts attributes[:method]
-
header_found, footer_found = false, false
@lines.each do |line|
line_def = file_format.line_definitions[line[:line_type]]
header_found = true if line_def.header
footer_found = true if line_def.footer
end
- header_found && footer_found
-
+ header_found && footer_found
end
- # Returns the line type of the parsed line of this request.
- # This function can only be called in single line mode.
- def line_type
- raise "Not a single line request!" unless single_line?
- lines.first[:line_type]
- end
-
# Returns the first timestamp encountered in a request.
def timestamp
first(:timestamp)
+ end
+
+ def first_lineno
+ @lines.first[:lineno]
+ end
+
+ def last_lineno
+ @lines.last[:lineno]
end
end
end
\ No newline at end of file