| Class | Irc::Bot::Auth::Command |
| In: |
lib/rbot/botuser.rb
|
| Parent: | Object |
An Irc::Bot::Auth::Command defines a command by its "path":
base::command::subcommand::subsubcommand::subsubsubcommand
| command | [R] | |
| path | [R] |
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"
# File lib/rbot/botuser.rb, line 91
91: def initialize(cmd)
92: cmdpath = sanitize_command_path(cmd).split('::')
93: seq = cmdpath.inject(["*"]) { |list, cmd|
94: list << (list.length > 1 ? list.last + "::" : "") + cmd
95: }
96: @path = seq.map { |k|
97: k.to_sym
98: }
99: @command = path.last
100: debug "Created command #{@command.inspect} with path #{@path.pretty_inspect}"
101: end
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
# File lib/rbot/botuser.rb, line 76
76: def sanitize_command_path(cmd)
77: pre = cmd.to_s.downcase.gsub(/^\*?(?:::)?/,"").gsub(/::$/,"")
78: return pre if pre.empty?
79: return pre if pre =~ /^\S+(::\S+)*$/
80: raise TypeError, "#{cmd.inspect} is not a valid command"
81: end