Class: HttpLogReader::Request
- Inherits:
-
Object
- Object
- HttpLogReader::Request
- Defined in:
- lib/http_log_reader.rb
Defined Under Namespace
Classes: RequestLine
Instance Attribute Summary collapse
-
#bytes_returned ⇒ Object
readonly
Returns the value of attribute bytes_returned.
-
#http_auth_userid ⇒ Object
readonly
Returns the value of attribute http_auth_userid.
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#referer ⇒ Object
readonly
Returns the value of attribute referer.
-
#remote_user_name ⇒ Object
readonly
Returns the value of attribute remote_user_name.
-
#request_line ⇒ Object
readonly
Returns the value of attribute request_line.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#time_finished ⇒ Object
readonly
Returns the value of attribute time_finished.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#initialize(line) ⇒ Request
constructor
A new instance of Request.
- #parse_time_finished(time_finished_raw) ⇒ Object
Constructor Details
#initialize(line) ⇒ Request
Returns a new instance of Request.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/http_log_reader.rb', line 28 def initialize( line ) line =~ %r|^(\S+) (\S+) (\S+) \[([^\]]+)\] "([^"]+)" (\S+) (\S+) "(\S+)" "([^"]+)"| @ip_address = $1 @remote_user_name = $2 unless $2 == '-' @http_auth_userid = $3 unless $3 == '-' time_finished_raw = $4 request_line_raw = $5 @status_code = $6.to_i @bytes_returned = $7.to_i unless $7 == '-' @referer = $8 unless $8 == '-' @user_agent = $9 @time_finished = parse_time_finished time_finished_raw @request_line = RequestLine.new request_line_raw end |
Instance Attribute Details
#bytes_returned ⇒ Object (readonly)
Returns the value of attribute bytes_returned.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def bytes_returned @bytes_returned end |
#http_auth_userid ⇒ Object (readonly)
Returns the value of attribute http_auth_userid.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def http_auth_userid @http_auth_userid end |
#ip_address ⇒ Object (readonly)
Returns the value of attribute ip_address.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def ip_address @ip_address end |
#referer ⇒ Object (readonly)
Returns the value of attribute referer.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def referer @referer end |
#remote_user_name ⇒ Object (readonly)
Returns the value of attribute remote_user_name.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def remote_user_name @remote_user_name end |
#request_line ⇒ Object (readonly)
Returns the value of attribute request_line.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def request_line @request_line end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def status_code @status_code end |
#time_finished ⇒ Object (readonly)
Returns the value of attribute time_finished.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def time_finished @time_finished end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
24 25 26 |
# File 'lib/http_log_reader.rb', line 24 def user_agent @user_agent end |
Instance Method Details
#parse_time_finished(time_finished_raw) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/http_log_reader.rb', line 43 def parse_time_finished( time_finished_raw ) time_finished_raw =~ %r{^(\d{2})/(\w{3})/(\d{4}):(\d{2}):(\d{2}):(\d{2}) (-|\+)(\d{2})(\d{2})} offset_direction = $7 offset_hours = $8.to_i offset_minutes = ( offset_hours * 60 ) + $9.to_i offset_seconds = offset_minutes * 60 time_finished = Time.utc( $3.to_i, $2, $1.to_i, $4.to_i, $5.to_i, $6.to_i ) if offset_direction == '+' time_finished = time_finished - offset_seconds else time_finished = time_finished + offset_seconds end time_finished end |