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

Counts the number of IP‘s and how much they‘ve surfed

Methods

add   add_user   from_hash   new   to_hash  

Attributes

users  [R]  The users(IP adresses) which made requests

Public Class methods

Creates a new IPCounter instance

[Source]

    # File xhochy/drossellog/ipcounter.rb, line 9
 9:       def initialize
10:         @users = {}
11:       end

Public Instance methods

Count another user, users are identified by their IP Input could be as String(1 Access), Hash and IPCounter(many users)

[Source]

    # File xhochy/drossellog/ipcounter.rb, line 34
34:       def add(data)
35:         if data.class == Hash
36:           # data is a Hash, so iterate through it
37:           data.each do |ip, value|
38:             if @users[ip] == nil
39:               @users[ip] = value
40:             else
41:               @users[ip] += value
42:             end
43:           end
44:         end #^ Hash
45:         
46:         if data.class == IPCounter
47:           data.users.each do |ip, value|
48:             if @users[ip] == nil
49:               @users[ip] = value
50:             else
51:               @users[ip] += value
52:             end
53:           end
54:         end #^ IPCounter
55:         
56:         if data.class == String
57:           if @users[data] == nil
58:             @users[data] = 1
59:           else
60:             @users[data] += 1
61:           end
62:         end #^ String
63:       end

Count another user, users are identified by their IP

[Source]

    # File xhochy/drossellog/ipcounter.rb, line 14
14:       def add_user(ip)
15:         if @users[ip] != nil
16:           @users[ip] += 1
17:         else
18:           @users[ip] = 1
19:         end
20:       end

import data from a Hash, overrides old data

[Source]

    # File xhochy/drossellog/ipcounter.rb, line 28
28:       def from_hash(data)
29:         @users = data.clone
30:       end

Return the data of this object as a hash

[Source]

    # File xhochy/drossellog/ipcounter.rb, line 23
23:       def to_hash
24:         @users.clone
25:       end

[Validate]