Class: Irc::Bot::Auth::Command
- Inherits:
-
Object
- Object
- Irc::Bot::Auth::Command
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb
Overview
An Irc::Bot::Auth::Command defines a command by its “path”:
base::command::subcommand::subsubcommand::subsubsubcommand
Instance Attribute Summary (collapse)
-
- (Object) command
readonly
Returns the value of attribute command.
-
- (Object) path
readonly
Returns the value of attribute path.
Instance Method Summary (collapse)
-
- (Command) initialize(cmd)
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.
-
- (Object) sanitize_command_path(cmd)
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.
-
- (Object) to_irc_auth_command
Returs self.
Constructor Details
- (Command) initialize(cmd)
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
Command.new("core::auth::save").path => [:"*", :"core", :"core::auth", :"core::auth::save"]
Command.new("core::auth::save").command => :"core::auth::save"
92 93 94 95 96 97 98 99 100 101 102 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 92 def initialize(cmd) cmdpath = sanitize_command_path(cmd).split('::') seq = cmdpath.inject(["*"]) { |list, cc| list << (list.length > 1 ? list.last + "::" : "") + cc } @path = seq.map { |k| k.to_sym } @command = path.last debug "Created command #{@command.inspect} with path #{@path.pretty_inspect}" end |
Instance Attribute Details
- (Object) command (readonly)
Returns the value of attribute command
72 73 74 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 72 def command @command end |
- (Object) path (readonly)
Returns the value of attribute path
72 73 74 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 72 def path @path end |
Instance Method Details
- (Object) sanitize_command_path(cmd)
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
77 78 79 80 81 82 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 77 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 |
- (Object) to_irc_auth_command
Returs self
105 106 107 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/botuser.rb', line 105 def to_irc_auth_command self end |