class Docopt::Option
Attributes
argcount[RW]
long[R]
short[R]
Public Class Methods
new(short=nil, long=nil, argcount=0, value=false)
click to toggle source
# File lib/docopt.rb, line 242 def initialize(short=nil, long=nil, argcount=0, value=false) unless [0, 1].include? argcount raise RuntimeError end @short, @long = short, long @argcount, @value = argcount, value if value == false and argcount > 0 @value = nil else @value = value end end
parse(option_description)
click to toggle source
# File lib/docopt.rb, line 257 def self.parse(option_description) short, long, argcount, value = nil, nil, 0, false options, _, description = option_description.strip.partition(' ') options = options.gsub(',', ' ').gsub('=', ' ') for s in options.split if s.start_with?('--') long = s elsif s.start_with?('-') short = s else argcount = 1 end end if argcount > 0 matched = description.scan(/\[default: (.*)\]/i) value = matched[0][0] if matched.count > 0 end new(short, long, argcount, value) end
Public Instance Methods
inspect()
click to toggle source
# File lib/docopt.rb, line 292 def inspect return "Option(#{self.short}, #{self.long}, #{self.argcount}, #{self.value})" end
name()
click to toggle source
# File lib/docopt.rb, line 288 def name return self.long ? self.long : self.short end
single_match(left)
click to toggle source
# File lib/docopt.rb, line 279 def single_match(left) left.each_with_index do |p, n| if self.name == p.name return [n, p] end end return [nil, nil] end