Class: OptimusPrime::Command
Instance Method Summary collapse
- #arity ⇒ Object
- #file ⇒ Object
- #help ⇒ Object
-
#initialize(handler, caller = nil) ⇒ Command
constructor
A new instance of Command.
- #line ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(handler, caller = nil) ⇒ Command
Returns a new instance of Command.
3 4 5 |
# File 'lib/optimus_prime/command.rb', line 3 def initialize(handler, caller=nil) @handler, @caller = handler, (caller && caller[1]) end |
Instance Method Details
#arity ⇒ Object
30 31 32 |
# File 'lib/optimus_prime/command.rb', line 30 def arity @handler.arity end |
#file ⇒ Object
22 23 24 |
# File 'lib/optimus_prime/command.rb', line 22 def file @file ||= File.read(@caller.split(':').first) end |
#help ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/optimus_prime/command.rb', line 7 def help @help ||= begin lines = file.split(/\n/) result = [] i = 0 while (string = lines[line+i]) =~ /\s*##?/ result << string.gsub(/^\s*#*\s?/, '') i += 1 end result.shift if result.first.empty? result.pop if result.last.empty? result.join("\n") end end |
#line ⇒ Object
26 27 28 |
# File 'lib/optimus_prime/command.rb', line 26 def line @caller.split(':').last.to_i end |
#to_proc ⇒ Object
34 35 36 37 38 39 |
# File 'lib/optimus_prime/command.rb', line 34 def to_proc case handler = @handler when Proc then handler else @handler.to_proc end end |