Class: Entry::Entry
- Inherits:
-
Object
- Object
- Entry::Entry
- Defined in:
- lib/data/entry.rb
Overview
Entity class to represent a standard logging entry of an nginx logfile
Instance Attribute Summary collapse
-
#element_size ⇒ Integer
readonly
The size of the result in bytes.
-
#http_referer ⇒ String
readonly
The site from where the request was issued.
-
#http_request ⇒ String
readonly
The http request.
-
#http_status ⇒ Integer
readonly
The http status.
-
#remote_user ⇒ String
readonly
The information of the remote user.
-
#source ⇒ String
readonly
The source address stored as a string.
-
#timestamp ⇒ Time
readonly
The timestamp of the representing entry.
-
#user_agent ⇒ String
readonly
The used browser program or user agent.
Instance Method Summary collapse
-
#initialize(input_string) ⇒ Entry
constructor
initialization.
-
#parse_integer(int_string) ⇒ Integer
private
helper method to parse the given string to an integer.
-
#parse_timestamp(time_string, time_zone) ⇒ Time
private
helper method to parse the timestamp from the time informations.
-
#to_string ⇒ String
method to get a formatted string.
Constructor Details
#initialize(input_string) ⇒ Entry
initialization
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/data/entry.rb', line 27 def initialize(input_string) @source = input_string[0] @remote_user = input_string[2] @timestamp = (input_string[3], input_string[4]) @http_request = input_string[5] @http_status = parse_integer(input_string[6]) @element_size = parse_integer(input_string[7]) @http_referer = input_string[8] @user_agent = input_string[9] end |
Instance Attribute Details
#element_size ⇒ Integer (readonly)
Returns the size of the result in bytes.
19 20 21 |
# File 'lib/data/entry.rb', line 19 def element_size @element_size end |
#http_referer ⇒ String (readonly)
Returns the site from where the request was issued.
21 22 23 |
# File 'lib/data/entry.rb', line 21 def http_referer @http_referer end |
#http_request ⇒ String (readonly)
Returns the http request.
15 16 17 |
# File 'lib/data/entry.rb', line 15 def http_request @http_request end |
#http_status ⇒ Integer (readonly)
Returns the http status.
17 18 19 |
# File 'lib/data/entry.rb', line 17 def http_status @http_status end |
#remote_user ⇒ String (readonly)
Returns the information of the remote user.
11 12 13 |
# File 'lib/data/entry.rb', line 11 def remote_user @remote_user end |
#source ⇒ String (readonly)
Returns the source address stored as a string.
9 10 11 |
# File 'lib/data/entry.rb', line 9 def source @source end |
#timestamp ⇒ Time (readonly)
Returns the timestamp of the representing entry.
13 14 15 |
# File 'lib/data/entry.rb', line 13 def @timestamp end |
#user_agent ⇒ String (readonly)
Returns the used browser program or user agent.
23 24 25 |
# File 'lib/data/entry.rb', line 23 def user_agent @user_agent end |
Instance Method Details
#parse_integer(int_string) ⇒ Integer (private)
helper method to parse the given string to an integer
60 61 62 |
# File 'lib/data/entry.rb', line 60 def parse_integer(int_string) Integer(int_string) end |
#parse_timestamp(time_string, time_zone) ⇒ Time (private)
helper method to parse the timestamp from the time informations
51 52 53 54 55 |
# File 'lib/data/entry.rb', line 51 def (time_string, time_zone) time_string.slice!(0) time_zone.chomp("]") Time.strptime(time_string.concat(time_zone), "%d/%b/%Y:%T%z") end |
#to_string ⇒ String
method to get a formatted string
40 41 42 43 |
# File 'lib/data/entry.rb', line 40 def to_string "#{@source} #{@remote_user} #{@timestamp} #{@http_request} "\ "#{@http_status} #{@element_size} byte #{@http_referer}\n#{@user_agent}" end |