Class: Fargo::SearchResult

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

Instance Method Summary collapse

Constructor Details

#initialize(file, filesize, client, target = nil) ⇒ SearchResult

Needs :file, :filesize, :client, :target (if passive)



5
6
7
# File 'lib/fargo/search_result.rb', line 5

def initialize file, filesize, client, target = nil
  @file, @filesize, @client, @target = file, filesize, client, target
end

Instance Method Details

#active_send(nick, ip, port) ⇒ Object



25
26
27
28
29
# File 'lib/fargo/search_result.rb', line 25

def active_send nick, ip, port
  socket = EventMachine.open_datagram_socket '0.0.0.0', 0
  socket.send_datagram "$SR #{nick} #{to_s}", ip, port
  socket.close_connection_after_writing
end

#to_sObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fargo/search_result.rb', line 9

def to_s
  file = @file.gusb '/', "\\"
  if File.directory? @file
    s = file
  else
    s = "#{file}\005#{@filesize}"
  end

  s << sprintf(" %d/%d\005%s (%s:%d)", @client.open_slots,
                                       @client.config.upload_slots,
                                       @client.hub.hubname,
                                       @client.config.hub_address,
                                       @client.config.hub_port)
  s << "\005#{@target}" if @client.config.passive
end