Class: Executable::Help::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/executable/help.rb

Overview

Encapsualtes a command line option.

Instance Method Summary collapse

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

#commentObject



389
390
391
# File 'lib/executable/help.rb', line 389

def comment
  @method.comment
end

#descriptionObject



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

#markObject



426
427
428
# File 'lib/executable/help.rb', line 426

def mark
  name.to_s.size == 1 ? '-' : '--'
end

#nameObject



385
386
387
# File 'lib/executable/help.rb', line 385

def name
  @method.name.to_s.chomp('!').chomp('=')
end

#parameterObject



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

#usageObject



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