Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 83 lines (71 sloc) 1.826 kb
0495e57 James Urquhart Somebody set us up the bomb
authored
1 class LogCollection
2 attr_accessor :entries
3 attr_accessor :senders
4 attr_accessor :source
5
6 def initialize
7 @entries = []
8 @senders = {}
9 @source = nil
10 end
11
12 def add_sender(sender)
13 idt = sender[:ident]
14
15 if idt
16 if @senders.has_key? idt
17 @senders[idt].merge(sender)
18 else
19 @senders[idt] = Sender.new(idt, sender[:name], sender[:hostmask])
20 end
21 else
22 # Look for sender[:name]/sender[:old_name]
23 name = sender[:old_name]||sender[:name]
24 matched_senders = @senders.select do |k, v|
f14e168 James Urquhart Add time limits for log entries, spec log collection.
authored
25 if v.name == name
0495e57 James Urquhart Somebody set us up the bomb
authored
26 true
27 else
28 false
29 end
30 end
f14e168 James Urquhart Add time limits for log entries, spec log collection.
authored
31 matched_senders.first ? matched_senders.first[1] : nil
0495e57 James Urquhart Somebody set us up the bomb
authored
32 end
33 end
34
35 def add_event(data)
36 sender = if data[:sender]
37 add_sender(data[:sender])
38 else
39 nil
40 end
41
42 log_entry = LogEntry.new(data, sender)
43 log_entry.source = @source
44
45 @entries << log_entry
46 end
f14e168 James Urquhart Add time limits for log entries, spec log collection.
authored
47
48 def limit_entries_by_time(start_time, end_time)
49 return if (start_time.nil? && end_time.nil?)
50 @entries.reject! do |entry|
51 if (start_time.nil? or entry.occurred >= start_time) && (end_time.nil? or entry.occurred < end_time)
52 false
53 else
54 true
55 end
56 end
57 end
0495e57 James Urquhart Somebody set us up the bomb
authored
58
59 def clean_entries
60 @entries.sort! { |x,y| x.occurred <=> y.occurred }
61
62 last_entry = nil
f14e168 James Urquhart Add time limits for log entries, spec log collection.
authored
63 @entries.reject! do |entry|
0495e57 James Urquhart Somebody set us up the bomb
authored
64 unless last_entry.nil?
65 rej = if entry.occurred == last_entry.occurred &&
66 entry.sender == last_entry.sender &&
67 entry.content.strip == last_entry.content.strip
68 puts "Rejected duplicate..."
69 puts entry.content
70 puts last_entry.content
71 true
72 else
73 false
74 end
75 end
76
77 last_entry = entry
78 rej
79 end
80 end
81
82
83 end
Something went wrong with that request. Please try again.