Class: Zircon

Inherits:
Object
  • Object
show all
Includes:
Callback
Defined in:
lib/zircon.rb,
lib/zircon/message.rb,
lib/zircon/version.rb,
lib/zircon/callback.rb,
lib/zircon/message/patterns.rb

Defined Under Namespace

Modules: Callback Classes: Message

Constant Summary collapse

COMMAND_NAMES =
%w[
  ADMIN
  AWAY
  CREDITS
  CYCLE
  DALINFO
  INVITE
  ISON
  JOIN
  KICK
  KNOCK
  LICENSE
  LINKS
  LIST
  LUSERS
  MAP
  MODE
  MOTD
  NAMES
  NICK
  NOTICE
  PART
  PASS
  PING
  PONG
  PRIVMSG
  QUIT
  RULES
  SETNAME
  SILENCE
  STATS
  TIME
  TOPIC
  USER
  USERHOST
  VERSION
  VHOST
  WATCH
  WHO
  WHOIS
  WHOWAS
  NUMERICREPLY
].freeze
VERSION =
"0.0.8"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Zircon

Returns a new instance of Zircon.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/zircon.rb', line 64

def initialize(args = {})
  @server       = args[:server]
  @port         = args[:port]
  @channel      = args[:channel]
  @password     = args[:password]
  @username     = args[:username]
  @nickname     = args[:nickname] || @username
  @realname     = args[:realname] || @username
  @use_ssl      = args[:use_ssl]  || false
  on_ping { |message| pong(message.raw) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zircon::Callback

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



10
11
12
# File 'lib/zircon.rb', line 10

def channel
  @channel
end

#nicknameObject

Returns the value of attribute nickname.



10
11
12
# File 'lib/zircon.rb', line 10

def nickname
  @nickname
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/zircon.rb', line 10

def port
  @port
end

#realnameObject

Returns the value of attribute realname.



10
11
12
# File 'lib/zircon.rb', line 10

def realname
  @realname
end

#serverObject

Returns the value of attribute server.



10
11
12
# File 'lib/zircon.rb', line 10

def server
  @server
end

#use_sslObject

Returns the value of attribute use_ssl.



10
11
12
# File 'lib/zircon.rb', line 10

def use_ssl
  @use_ssl
end

#usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/zircon.rb', line 10

def username
  @username
end

Instance Method Details

#loginObject



87
88
89
90
91
92
# File 'lib/zircon.rb', line 87

def 
  pass @password if @password
  nick @nickname
  user @username, 0, "*", ":" + @realname
  join @channel if @channel
end

#run!Object



76
77
78
79
# File 'lib/zircon.rb', line 76

def run!
  
  wait_message
end

#wait_messageObject

Start blocking-loop. Call trigger_message and trigger_xxx on a message received. (xxx is determined by the command type of the message)



97
98
99
100
101
102
103
# File 'lib/zircon.rb', line 97

def wait_message
  loop do
    message = Message.new(gets)
    trigger_message(message)
    send("trigger_#{message.type}", message)
  end
end