Class: IRC::Event
- Inherits:
-
Object
- Object
- IRC::Event
- Defined in:
- lib/em-ruby-irc/IRC-Event.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#hostmask ⇒ Object
readonly
Returns the value of attribute hostmask.
-
#logged_in ⇒ Object
Returns the value of attribute logged_in.
-
#message ⇒ Object
Returns the value of attribute message.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(data, connection) ⇒ Event
constructor
A new instance of Event.
- #run_handlers(event_type) ⇒ Object
Constructor Details
#initialize(data, connection) ⇒ Event
Returns a new instance of Event.
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 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 18 def initialize(data, connection) @connection = connection @logged_in = false data.chomp! data.sub!(/^:/, '') mess_parts = data.split(':', 2); unless mess_parts.nil? or mess_parts.size < 2 # mess_parts[0] is server info # mess_parts[1] is the message that was sent = mess_parts[1] @stats = mess_parts[0].scan(/[\/\=\-\_\~\"\`\|\^\{\}\[\]\w.\#\@\+]+/) unless @stats[0].nil? if @stats[0].match(/^PING/) @event_type = 'ping' elsif @stats[1] && @stats[1].match(/^\d+$/) @event_type = EventLookup::find_by_number(@stats[1]); @channel = @stats[3].downcase unless @stats[3].nil? @channel = @stats[3] if @stats[3].nil? else @event_type = @stats[2].downcase if @stats[2] end if @event_type != 'ping' @from = @stats[0].downcase end # FIXME: this list would probably be more accurate to exclude commands than to include them @hostmask = @stats[1] if %W(topic privmsg join).include? @event_type @channel = @stats[3].downcase if @stats[3] && !@channel @target = @stats[5].downcase if @stats[5] @mode = @stats[4] if @stats[4] run_handlers(@event_type) unless @event_type.nil? end end #logger.debug(data) end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
16 17 18 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 16 def channel @channel end |
#connection ⇒ Object
Returns the value of attribute connection.
17 18 19 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 17 def connection @connection end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
16 17 18 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 16 def event_type @event_type end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
16 17 18 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 16 def from @from end |
#hostmask ⇒ Object (readonly)
Returns the value of attribute hostmask.
16 17 18 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 16 def hostmask @hostmask end |
#logged_in ⇒ Object
Returns the value of attribute logged_in.
17 18 19 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 17 def logged_in @logged_in end |
#message ⇒ Object
Returns the value of attribute message.
17 18 19 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 17 def end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
16 17 18 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 16 def mode @mode end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
16 17 18 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 16 def stats @stats end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
16 17 18 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 16 def target @target end |
Instance Method Details
#run_handlers(event_type) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/em-ruby-irc/IRC-Event.rb', line 55 def run_handlers(event_type) begin return if connection.irc_handlers.size == 0 or connection.irc_handlers[event_type].nil? connection.irc_handlers[event_type].each do |handler| handler.call(self) unless handler.nil? end rescue => err log_error(err) end end |