Class: VisitorRecord

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, browser) ⇒ VisitorRecord

Returns a new instance of VisitorRecord.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/VisitorRecord.rb', line 21

def initialize(ip, browser)
  @hits = []
  @ip = ip
  @firstHit = nil
  @lastHit = nil
  @firstPage = nil
  @lastPage = nil
  @browser = browser
  @pageCount = 0
  @robot = nil
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def browser
  @browser
end

#firstHitObject (readonly)

Returns the value of attribute firstHit.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def firstHit
  @firstHit
end

#firstPageObject (readonly)

Returns the value of attribute firstPage.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def firstPage
  @firstPage
end

#hitsObject (readonly)

Returns the value of attribute hits.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def hits
  @hits
end

#ipObject (readonly)

Returns the value of attribute ip.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def ip
  @ip
end

#lastHitObject (readonly)

Returns the value of attribute lastHit.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def lastHit
  @lastHit
end

#lastPageObject (readonly)

Returns the value of attribute lastPage.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def lastPage
  @lastPage
end

#pageCountObject (readonly)

Returns the value of attribute pageCount.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def pageCount
  @pageCount
end

#robotObject

Returns the value of attribute robot.



17
18
19
# File 'lib/VisitorRecord.rb', line 17

def robot
  @robot
end

Instance Method Details

#addHit(hit) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/VisitorRecord.rb', line 33

def addHit(hit)
  @firstHit = hit if @firstHit == nil
  @lastHit = hit
  @hits.push(hit)
  hit.visitor = self

  if hit.page.isPage
    # Remove old exit page flag from previous last page
    @lastPage.exit = false if @lastPage
    hit.exit = true
    @pageCount += 1
    if @firstPage == nil
      @firstPage = hit
      hit.entry = true
    end
    @lastPage = hit
  end
end

#bytesObject



71
72
73
74
75
76
77
# File 'lib/VisitorRecord.rb', line 71

def bytes
  bytes = 0
  @hits.each do |h|
    bytes += h.bytes
  end
  return bytes
end

#cityObject



90
91
92
# File 'lib/VisitorRecord.rb', line 90

def city
  $geoLocator.city(ip)
end

#countryObject



86
87
88
# File 'lib/VisitorRecord.rb', line 86

def country
  $geoLocator.country(ip)
end

#hitCountObject



67
68
69
# File 'lib/VisitorRecord.rb', line 67

def hitCount
  return @hits.length()
end

#hostObject



63
64
65
# File 'lib/VisitorRecord.rb', line 63

def host
  return $resolver.hostName(@ip)
end

#purge(deadline) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/VisitorRecord.rb', line 52

def purge(deadline)
  @hits.each do |h|
    if h.timeStamp < deadline
      @hits.delete(h)
    else
      return false
    end
  end
  @hits.empty?
end

#refererObject



79
80
81
82
83
84
# File 'lib/VisitorRecord.rb', line 79

def referer
  @hits.each do |h|
    return h.referer if h.referer != nil && h.referer.external?
  end
  return nil
end