-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz1k.rb
56 lines (49 loc) · 1.38 KB
/
z1k.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'drb/drb'
SERVER_URI="druby://localhost:9000"
DRb.start_service
class Client
def initialize
@log_service = DRbObject.new_with_uri(SERVER_URI) #utworzenie instancji obiektu połączonego z serwerem
@id = @log_service.as_id
end
def send(message) #wysyłanie komunikatu
if @log_service.respond_to?('save')
@log_service.save(@id, message) #podajemy id programu i komunikat jako argumenty funkcji save na serwerze
end
end
#metoda raportk wyszukuje komunikaty z podanego zakresu czasu, pasujące do podanego wyrażenia regularnego
#metoda ta zwraca kod html, w którym znajduje się tabela z komunikatami spełniającymi podane kryteria dla danego programu
def raportk(from, to, re)
if @log_service.respond_to?('raport')
@log_service.raport(from, to, @id, re)
end
end
end
p1 = Client.new
p2 = Client.new
p3 = Client.new
puts "Jeśli chcesz dodać komunikat wpisz 1"
puts "Jeśli chcesz zakończyć dodawanie komunikatów wpisz coś innego niż 1"
while(napis = gets)
napis.chomp!
if napis == '1'
puts "Wybierz który program wysyła komunikat (wpisz 1, 2 lub 3)"
nr = gets
nr.chomp!
puts "Podaj komunikat programu nr "+nr
k = gets
k.chomp!
if(nr == '1')
p1.send(k)
elsif(nr == '2')
p2.send(k)
elsif(nr == '3')
p3.send(k)
end
else
break
end
end
File.open("raporty.html", "w") do |f|
f.puts p1.raportk(0, Time.now, /komunikat|Coś/)
end