Class: Irc::Bot::Auth::Command
Overview
An Irc::Bot::Auth::Command defines a command by its “path”:
base::command::subcommand::subsubcommand::subsubsubcommand
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(cmd) ⇒ Command
constructor
Creates a new Command from a given string; you can then access the command as a symbol with the :command method and the whole path as :path.
-
#sanitize_command_path(cmd) ⇒ Object
A method that checks if a given cmd is in a form that can be reduced into a canonical command path, and if so, returns it.
-
#to_irc_auth_command ⇒ Object
Returs self.
Constructor Details
#initialize(cmd) ⇒ Command
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rbot/botuser.rb', line 91 def initialize(cmd) cmdpath = sanitize_command_path(cmd).split('::') seq = cmdpath.inject(["*"]) { |list, cmd| list << (list.length > 1 ? list.last + "::" : "") + cmd } @path = seq.map { |k| k.to_sym } @command = path.last debug "Created command #{@command.inspect} with path #{@path.pretty_inspect}" end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
71 72 73 |
# File 'lib/rbot/botuser.rb', line 71 def command @command end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
71 72 73 |
# File 'lib/rbot/botuser.rb', line 71 def path @path end |
Instance Method Details
#sanitize_command_path(cmd) ⇒ Object
A method that checks if a given cmd is in a form that can be reduced into a canonical command path, and if so, returns it
76 77 78 79 80 81 |
# File 'lib/rbot/botuser.rb', line 76 def sanitize_command_path(cmd) pre = cmd.to_s.downcase.gsub(/^\*?(?:::)?/,"").gsub(/::$/,"") return pre if pre.empty? return pre if pre =~ /^\S+(::\S+)*$/ raise TypeError, "#{cmd.inspect} is not a valid command" end |
#to_irc_auth_command ⇒ Object
Returs self
104 105 106 |
# File 'lib/rbot/botuser.rb', line 104 def to_irc_auth_command self end |