Class: LogParser::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/logparser/line.rb

Instance Method Summary collapse

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

#bytesObject



42
43
44
# File 'lib/logparser/line.rb', line 42

def bytes
  @bytes ||= raw_fields[:bytes].to_i
end

#domainObject



18
19
20
# File 'lib/logparser/line.rb', line 18

def domain
  @domain ||= decode_string(raw_fields[:domain])
end

#hostObject



14
15
16
# File 'lib/logparser/line.rb', line 14

def host
  @host ||= decode_string(raw_fields[:host])
end

#pathObject



30
31
32
# File 'lib/logparser/line.rb', line 30

def path
  @path ||= raw_fields[:path]
end

#protocolObject



34
35
36
# File 'lib/logparser/line.rb', line 34

def protocol
  @protocol ||= raw_fields[:protocol]
end

#raw_fieldsObject



10
11
12
# File 'lib/logparser/line.rb', line 10

def raw_fields
  @raw_fields ||= @template.apply(@raw)
end

#referrerObject



46
47
48
# File 'lib/logparser/line.rb', line 46

def referrer
  @referrer ||= decode_string(raw_fields[:referrer])
end

#statusObject



38
39
40
# File 'lib/logparser/line.rb', line 38

def status
  @status ||= raw_fields[:status].to_i
end

#time_takenObject



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

#timestampObject



22
23
24
# File 'lib/logparser/line.rb', line 22

def timestamp
  @timestamp ||= DateTime.strptime(raw_fields[:timestamp], '%d/%b/%Y:%H:%M:%S %Z')
end

#user_agentObject



50
51
52
# File 'lib/logparser/line.rb', line 50

def user_agent
  @user_agent ||= decode_string(raw_fields[:user_agent])
end

#verbObject



26
27
28
# File 'lib/logparser/line.rb', line 26

def verb
  @verb ||= raw_fields[:verb].downcase.to_sym
end