Class: HTTPLogAnalyzer::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/http-log-analyzer/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Entry

Returns a new instance of Entry.



12
13
14
15
16
17
18
19
20
# File 'lib/http-log-analyzer/entry.rb', line 12

def initialize(info)
  # 12/Feb/2016:09:59:04 +0000
  @timestamp = DateTime.strptime(info[:datetime], '%d/%b/%Y:%H:%M:%S %Z')
  @source = Element::Source.parse(info[:ip])
  @request = Element::Request.parse(info[:request])
  @status = Element::Status.parse(info[:status])
  @referer = Element::Referer.parse(info[:referer])
  @user_agent = Element::UserAgent.parse(info[:user_agent])
end

Instance Attribute Details

#refererObject

Returns the value of attribute referer.



9
10
11
# File 'lib/http-log-analyzer/entry.rb', line 9

def referer
  @referer
end

#requestObject

Returns the value of attribute request.



7
8
9
# File 'lib/http-log-analyzer/entry.rb', line 7

def request
  @request
end

#sourceObject

Returns the value of attribute source.



6
7
8
# File 'lib/http-log-analyzer/entry.rb', line 6

def source
  @source
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/http-log-analyzer/entry.rb', line 8

def status
  @status
end

#timestampObject

Returns the value of attribute timestamp.



5
6
7
# File 'lib/http-log-analyzer/entry.rb', line 5

def timestamp
  @timestamp
end

#user_agentObject

Returns the value of attribute user_agent.



10
11
12
# File 'lib/http-log-analyzer/entry.rb', line 10

def user_agent
  @user_agent
end

Instance Method Details

#calendar_weekObject



22
23
24
# File 'lib/http-log-analyzer/entry.rb', line 22

def calendar_week
  '%s - %s' % [1, 7].map { |d| DateTime.commercial(@timestamp.year, @timestamp.cweek, d).to_date }
end