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.



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

#commentObject



395
396
397
# File 'lib/executable/help.rb', line 395

def comment
  @method.comment
end

#descriptionObject



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

#markObject



432
433
434
# File 'lib/executable/help.rb', line 432

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

#nameObject



391
392
393
# File 'lib/executable/help.rb', line 391

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

#parameterObject



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

#usageObject



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