Class: Recheck::Optimist::LongNames
- Inherits:
-
Object
- Object
- Recheck::Optimist::LongNames
- Defined in:
- lib/recheck/vendor/optimist.rb
Instance Method Summary collapse
-
#initialize ⇒ LongNames
constructor
A new instance of LongNames.
-
#long ⇒ Object
long specified with :long has precedence over the true-name.
- #make_valid(lopt) ⇒ Object
-
#names ⇒ Object
all valid names, including alts.
- #set(name, lopt, alts) ⇒ Object
Constructor Details
#initialize ⇒ LongNames
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
#long ⇒ Object
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 |
#names ⇒ Object
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 |