Class: Executable::Help::Option
- Inherits:
-
Object
- Object
- Executable::Help::Option
- Defined in:
- lib/executable/help.rb
Overview
Encapsualtes a command line option.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #comment ⇒ Object
- #description ⇒ Object
-
#description=(desc) ⇒ Object
Set description manually.
-
#initialize(method) ⇒ Option
constructor
A new instance of Option.
- #mark ⇒ Object
- #name ⇒ Object
- #parameter ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(method) ⇒ Option
Returns a new instance of Option.
381 382 383 |
# File 'lib/executable/help.rb', line 381 def initialize(method) @method = method end |
Instance Method Details
#<=>(other) ⇒ Object
421 422 423 |
# File 'lib/executable/help.rb', line 421 def <=>(other) self.name <=> other.name end |
#comment ⇒ Object
389 390 391 |
# File 'lib/executable/help.rb', line 389 def comment @method.comment end |
#description ⇒ Object
393 394 395 |
# File 'lib/executable/help.rb', line 393 def description @description ||= comment.split("\n").first end |
#description=(desc) ⇒ Object
Set description manually.
398 399 400 |
# File 'lib/executable/help.rb', line 398 def description=(desc) @description = desc end |
#mark ⇒ Object
426 427 428 |
# File 'lib/executable/help.rb', line 426 def mark name.to_s.size == 1 ? '-' : '--' end |
#name ⇒ Object
385 386 387 |
# File 'lib/executable/help.rb', line 385 def name @method.name.to_s.chomp('!').chomp('=') end |
#parameter ⇒ Object
402 403 404 405 406 407 408 409 410 |
# File 'lib/executable/help.rb', line 402 def parameter begin @method.owner.instance_method(@method.name.to_s.chomp('=') + '?') false rescue param = @method.parameters.first param.last if param end end |
#usage ⇒ Object
413 414 415 416 417 418 419 |
# File 'lib/executable/help.rb', line 413 def usage if parameter "#{name}=#{parameter.to_s.upcase}" else "#{name}" end end |