Class: LogParser::Line
- Inherits:
-
Object
- Object
- LogParser::Line
- Defined in:
- lib/logparser/line.rb
Instance Method Summary collapse
- #bytes ⇒ Object
- #domain ⇒ Object
- #host ⇒ Object
-
#initialize(template, raw) ⇒ Line
constructor
A new instance of Line.
- #path ⇒ Object
- #protocol ⇒ Object
- #raw_fields ⇒ Object
- #referrer ⇒ Object
- #status ⇒ Object
- #time_taken ⇒ Object
- #timestamp ⇒ Object
- #user_agent ⇒ Object
- #verb ⇒ Object
Constructor Details
#initialize(template, raw) ⇒ Line
Returns a new instance of Line.
5 6 7 8 |
# File 'lib/logparser/line.rb', line 5 def initialize(template, raw) @template = template @raw = raw.strip end |
Instance Method Details
#bytes ⇒ Object
42 43 44 |
# File 'lib/logparser/line.rb', line 42 def bytes @bytes ||= raw_fields[:bytes].to_i end |
#domain ⇒ Object
18 19 20 |
# File 'lib/logparser/line.rb', line 18 def domain @domain ||= decode_string(raw_fields[:domain]) end |
#host ⇒ Object
14 15 16 |
# File 'lib/logparser/line.rb', line 14 def host @host ||= decode_string(raw_fields[:host]) end |
#path ⇒ Object
30 31 32 |
# File 'lib/logparser/line.rb', line 30 def path @path ||= raw_fields[:path] end |
#protocol ⇒ Object
34 35 36 |
# File 'lib/logparser/line.rb', line 34 def protocol @protocol ||= raw_fields[:protocol] end |
#raw_fields ⇒ Object
10 11 12 |
# File 'lib/logparser/line.rb', line 10 def raw_fields @raw_fields ||= @template.apply(@raw) end |
#referrer ⇒ Object
46 47 48 |
# File 'lib/logparser/line.rb', line 46 def referrer @referrer ||= decode_string(raw_fields[:referrer]) end |
#status ⇒ Object
38 39 40 |
# File 'lib/logparser/line.rb', line 38 def status @status ||= raw_fields[:status].to_i end |
#time_taken ⇒ Object
54 55 56 |
# File 'lib/logparser/line.rb', line 54 def time_taken @time_taken ||= raw_fields[:time_taken] ? raw_fields[:time_taken].to_f : nil end |
#timestamp ⇒ Object
22 23 24 |
# File 'lib/logparser/line.rb', line 22 def @timestamp ||= DateTime.strptime(raw_fields[:timestamp], '%d/%b/%Y:%H:%M:%S %Z') end |
#user_agent ⇒ Object
50 51 52 |
# File 'lib/logparser/line.rb', line 50 def user_agent @user_agent ||= decode_string(raw_fields[:user_agent]) end |
#verb ⇒ Object
26 27 28 |
# File 'lib/logparser/line.rb', line 26 def verb @verb ||= raw_fields[:verb].downcase.to_sym end |