Class: APRIL::Socket

Inherits:
Object
  • Object
show all
Includes:
PARSER
Defined in:
lib/april/socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PARSER

#handle

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/april/socket.rb', line 9

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



9
10
11
# File 'lib/april/socket.rb', line 9

def server
  @server
end

#socketObject (readonly)

Returns the value of attribute socket.



9
10
11
# File 'lib/april/socket.rb', line 9

def socket
  @socket
end

Instance Method Details

#connect(server, port) ⇒ Object



11
12
13
14
15
16
# File 'lib/april/socket.rb', line 11

def connect(server, port)
  @server = server
  @port = port

  @socket = TCPSocket.new(@server, @port)
end

#join(channels) ⇒ Object

Send JOIN command



41
42
43
44
45
# File 'lib/april/socket.rb', line 41

def join(channels)
  channels.each do |channel|
    write("JOIN ##{channel}")
  end
end

#listenObject



23
24
25
26
27
28
# File 'lib/april/socket.rb', line 23

def listen
  until @socket.eof? do
    puts "<< #{@socket.gets}"
    self.handle (@socket.gets)
  end
end

#nick(nick) ⇒ Object

Send NICK command



31
32
33
# File 'lib/april/socket.rb', line 31

def nick(nick)
  write("NICK #{nick}")
end

#user(user, realname) ⇒ Object

Send USER command



36
37
38
# File 'lib/april/socket.rb', line 36

def user(user, realname)
  write("USER #{user} * * :#{realname}")
end

#write(msg) ⇒ Object



18
19
20
21
# File 'lib/april/socket.rb', line 18

def write(msg)
  puts ">> #{msg}"
  @socket.write "#{msg}\n"
end