Class XhochY::Drossellog::LogLine
In: xhochy/drossellog/logline.rb
Parent: Object
PageCounter EntryCounter ImpressionCounter DataCounter LogFileParser WeeklyReport CodeCounter MonthlyReport LogLine DailyReport DailyIPCounter IPCounter ImpressionBlacklist Drossellog XhochY dot/f_1.png

Represents a line in a Apache combined-style logfile

Methods

Attributes

agent  [R]  The requesting user agent
day  [R]  The day where the request was made
hour  [R]  The hour where the request was made
http_code  [R]  The answered HTTP code form the server
ip  [R]  The IP which made the request
line  [R]  The whole line
method  [R]  The method used to make the request
minute  [R]  The minute where the request was made
month  [R]  The month where the request was made
path  [R]  The requested path
referrer  [R]  The referrer which took the client to this point
second  [R]  The second where the request was made
size  [R]  The size of the content sent back to the client
timezone  [R]  The timezone of the server at the time of the request
year  [R]  The year where the request was made

Public Class methods

return the regular expression for parsing a apache-combined logfile line

[Source]

    # File xhochy/drossellog/logline.rb, line 45
45:       def self.get_rxp
46:         @@rxp
47:       end

check if the line is a valid apache-combined logfile line

[Source]

    # File xhochy/drossellog/logline.rb, line 40
40:       def self.matches?(line)
41:         ('line' =~ @@rxp)
42:       end

Create a new instance of a XYLogLine object

[Source]

     # File xhochy/drossellog/logline.rb, line 154
154:       def initialize(arg)
155:         if arg.class == String
156:           init_with_string arg
157:         end
158:         if arg.class == Hash 
159:           init_with_hash arg
160:         end
161:       end

Public Instance methods

(re)initialize the object with data from a hash

[Source]

    # File xhochy/drossellog/logline.rb, line 50
50:       def init_with_hash(hash)
51:         @line = hash['line']
52:         @day = hash['day']
53:         @ip = hash['ip']
54:         @month = hash['month']
55:         @year = hash['year']
56:         @hour = hash['hour']
57:         @minute = hash['minute']
58:         @second = hash['second']
59:         @timezone = hash['timezone']
60:         @method = hash['method']
61:         @path = hash['path']
62:         @http_code = hash['http_code']
63:         @size = hash['size']
64:         @referrer = hash['referrer']
65:         @agent = hash['agent']
66:       end

(re)initialize the object with data from a string

[Source]

    # File xhochy/drossellog/logline.rb, line 69
69:       def init_with_string(line)
70:         @line = line
71:         matches = @@rxp.match(line)
72:         @ip = matches[1]
73:         # matches[2] -> user ..
74:         # matches[3] -> user ..
75:         @day = matches[4].to_i
76:         @month = matches[5]
77:         @year = matches[6].to_i
78:         @hour = matches[7].to_i
79:         @minute = matches[8].to_i
80:         @second = matches[9].to_i
81:         @timezone = matches[10]
82:         @method = matches[11]
83:         @path = matches[12] 
84:         @http_code = matches[13]
85:         @size = matches[14].to_i
86:         @referrer = matches[15]
87:         @agent = matches[16]
88:       end

Returns this line as a Hash object

[Source]

     # File xhochy/drossellog/logline.rb, line 91
 91:       def to_hash(strip_tags)
 92:         hash = {}
 93:         
 94:         if !strip_tags.include?('ip')
 95:           hash['ip'] = @ip
 96:         end
 97:         
 98:         if !strip_tags.include?('day')
 99:           hash['day'] = @day
100:         end
101:         
102:         if !strip_tags.include?('month')
103:           hash['month'] = @month
104:         end
105:         
106:         if !strip_tags.include?('year')
107:           hash['year'] = @year
108:         end
109:         
110:         if !strip_tags.include?('hour')
111:           hash['hour'] = @hour
112:         end
113:         
114:         if !strip_tags.include?('minute')
115:           hash['minute'] = @minute
116:         end
117:         
118:         if !strip_tags.include?('second')
119:           hash['second'] = @second
120:         end
121:         
122:         if !strip_tags.include?('timezone')
123:           hash['timezone'] = @timezone
124:         end
125:         
126:         if !strip_tags.include?('method')
127:           hash['method'] = @method
128:         end
129:         
130:         if !strip_tags.include?('path')
131:           hash['path'] = @path
132:         end
133:         
134:         if !strip_tags.include?('http_code')
135:           hash['http_code'] = @http_code
136:         end
137:         
138:         if !strip_tags.include?('size')
139:           hash['size'] = @size
140:         end
141:         
142:         if !strip_tags.include?('referrer')
143:           hash['referrer'] = @referrer
144:         end
145:         
146:         if !strip_tags.include?('agent')
147:           hash['agent'] = @agent
148:         end
149:         
150:         hash
151:       end

[Validate]