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.
387 388 389 |
# File 'lib/executable/help.rb', line 387 def initialize(method) @method = method end |
Instance Method Details
#<=>(other) ⇒ Object
427 428 429 |
# File 'lib/executable/help.rb', line 427 def <=>(other) self.name <=> other.name end |
#comment ⇒ Object
395 396 397 |
# File 'lib/executable/help.rb', line 395 def comment @method.comment end |
#description ⇒ Object
399 400 401 |
# File 'lib/executable/help.rb', line 399 def description @description ||= comment.split("\n").first end |
#description=(desc) ⇒ Object
Set description manually.
404 405 406 |
# File 'lib/executable/help.rb', line 404 def description=(desc) @description = desc end |
#mark ⇒ Object
432 433 434 |
# File 'lib/executable/help.rb', line 432 def mark name.to_s.size == 1 ? '-' : '--' end |
#name ⇒ Object
391 392 393 |
# File 'lib/executable/help.rb', line 391 def name @method.name.to_s.chomp('!').chomp('=') end |
#parameter ⇒ Object
408 409 410 411 412 413 414 415 416 |
# File 'lib/executable/help.rb', line 408 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
419 420 421 422 423 424 425 |
# File 'lib/executable/help.rb', line 419 def usage if parameter "#{name}=#{parameter.to_s.upcase}" else "#{name}" end end |