Class: Recheck::Optimist::LongNames

Inherits:
Object
  • Object
show all
Defined in:
lib/recheck/vendor/optimist.rb

Instance Method Summary collapse

Constructor Details

#initializeLongNames

Returns a new instance of LongNames.



709
710
711
712
713
# File 'lib/recheck/vendor/optimist.rb', line 709

def initialize
  @truename = nil
  @long = nil
  @alts = []
end

Instance Method Details

#longObject

long specified with :long has precedence over the true-name



733
734
735
# File 'lib/recheck/vendor/optimist.rb', line 733

def long
  @long || @truename
end

#make_valid(lopt) ⇒ Object



715
716
717
718
719
720
721
722
# File 'lib/recheck/vendor/optimist.rb', line 715

def make_valid(lopt)
  return nil if lopt.nil?
  case lopt.to_s
  when /^--([^-].*)$/ then $1
  when /^[^-]/ then lopt.to_s
  else raise ArgumentError, "invalid long option name #{lopt.inspect}"
  end
end

#namesObject

all valid names, including alts



738
739
740
# File 'lib/recheck/vendor/optimist.rb', line 738

def names
  [long] + @alts
end

#set(name, lopt, alts) ⇒ Object



724
725
726
727
728
729
730
# File 'lib/recheck/vendor/optimist.rb', line 724

def set(name, lopt, alts)
  @truename = name
  lopt = lopt ? lopt.to_s : name.to_s.tr("_", "-")
  @long = make_valid(lopt)
  alts = [alts] unless alts.is_a?(Array) # box the value
  @alts = alts.map { |alt| make_valid(alt) }.compact
end