Class: OptimistXL::LongNames
- Inherits:
-
Object
- Object
- OptimistXL::LongNames
- Defined in:
- lib/optimist_xl.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.
792 793 794 795 796 |
# File 'lib/optimist_xl.rb', line 792 def initialize @truename = nil @long = nil @alts = [] end |
Instance Method Details
#long ⇒ Object
long specified with :long has precedence over the true-name
816 |
# File 'lib/optimist_xl.rb', line 816 def long ; @long || @truename ; end |
#make_valid(lopt) ⇒ Object
798 799 800 801 802 803 804 805 |
# File 'lib/optimist_xl.rb', line 798 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
819 820 821 |
# File 'lib/optimist_xl.rb', line 819 def names [long] + @alts end |
#set(name, lopt, alts) ⇒ Object
807 808 809 810 811 812 813 |
# File 'lib/optimist_xl.rb', line 807 def set(name, lopt, alts) @truename = name lopt = lopt ? lopt.to_s : name.to_s.gsub("_", "-") @long = make_valid(lopt) alts = [alts] unless alts.is_a?(Array) # box the value @alts = alts.map { |alt| make_valid(alt) }.compact end |