Class: Marvin::Parsers::Command
- Inherits:
-
Object
- Object
- Marvin::Parsers::Command
- Defined in:
- lib/marvin/parsers/command.rb
Overview
A single incoming / outgoing irc command, with handy utilities to convert it to a Marvin::IRC::Event instance.
Constant Summary collapse
- @@commands =
{}
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#params ⇒ Object
Returns the value of attribute params.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(raw) ⇒ Command
constructor
Create a new command from the given raw message.
-
#to_event ⇒ Object
From the given command and arguments / params, attempt to recognize the command and convert it to an event which can be used for other stuff.
Constructor Details
#initialize(raw) ⇒ Command
Create a new command from the given raw message.
14 15 16 17 |
# File 'lib/marvin/parsers/command.rb', line 14 def initialize(raw) self.raw = raw self.params = [] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
10 11 12 |
# File 'lib/marvin/parsers/command.rb', line 10 def code @code end |
#params ⇒ Object
Returns the value of attribute params.
10 11 12 |
# File 'lib/marvin/parsers/command.rb', line 10 def params @params end |
#prefix ⇒ Object
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/marvin/parsers/command.rb', line 10 def prefix @prefix end |
#raw ⇒ Object
Returns the value of attribute raw.
10 11 12 |
# File 'lib/marvin/parsers/command.rb', line 10 def raw @raw end |
Instance Method Details
#to_event ⇒ Object
From the given command and arguments / params, attempt to recognize the command and convert it to an event which can be used for other stuff.
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 |
# File 'lib/marvin/parsers/command.rb', line 22 def to_event # If we have a numeric... if @code =~ /^\d+$/ ev = @@commands[:numeric].dup data = @params[0..-2] data << "#{@params.last.include?(" ") ? ":" : ""}#{@params.last}" ev.raw_arguments = [self.code.to_s, data.join(" ")] elsif code == "PRIVMSG" && params.last =~ /^\001(.*)\001$/ results = $1.to_s if results =~ /^ACTION / name, value = :action, results.gsub(/^ACTION /, '') else name, value = :ctcp, results end self.params[-1] = value ev = @@commands[name].dup ev.raw_arguments = self.params else ev = @@commands[self.code.to_sym] return nil if ev.nil? ev = ev.dup ev.raw_arguments = self.params end ev.prefix = self.prefix return ev end |