Class: Flumtter::Command
- Inherits:
-
Object
- Object
- Flumtter::Command
- Defined in:
- lib/flumtter/app/core/command.rb
Defined Under Namespace
Modules: DM, Tweet, User, UserList
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(command, help = "", &blk) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(command, help = "", &blk) ⇒ Command
Returns a new instance of Command.
4 5 6 7 8 9 |
# File 'lib/flumtter/app/core/command.rb', line 4 def initialize(command, help="", &blk) @name = command.is_a?(Regexp) ? command.inspect : command @command = command.is_a?(String) ? command.to_reg : command @help = help @blk = blk end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
3 4 5 |
# File 'lib/flumtter/app/core/command.rb', line 3 def command @command end |
#help ⇒ Object (readonly)
Returns the value of attribute help.
3 4 5 |
# File 'lib/flumtter/app/core/command.rb', line 3 def help @help end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/flumtter/app/core/command.rb', line 3 def name @name end |
Class Method Details
.list(commands) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/flumtter/app/core/command.rb', line 15 def self.list(commands) char_len = commands.max_by{|c|c.name.size}.name.size + 1 rescue 0 commands.map do |c| c.name.ljust(char_len) + c.help end.join("\n") end |
Instance Method Details
#call(*args) ⇒ Object
11 12 13 |
# File 'lib/flumtter/app/core/command.rb', line 11 def call(*args) @blk.call(*args) end |