Class: Docopt::Option
- Inherits:
-
Object
- Object
- Docopt::Option
- Defined in:
- lib/pwqgen/docopt.rb
Instance Attribute Summary collapse
-
#argcount ⇒ Object
readonly
Returns the value of attribute argcount.
-
#long ⇒ Object
readonly
Returns the value of attribute long.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #getopt ⇒ Object
-
#initialize(parse) ⇒ Option
constructor
A new instance of Option.
- #inspect ⇒ Object
- #set_value(val) ⇒ Object
- #symbols ⇒ Object
- #synonyms ⇒ Object
Constructor Details
#initialize(parse) ⇒ Option
Returns a new instance of Option.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pwqgen/docopt.rb', line 31 def initialize parse @argcount = 0 , _, description = parse.strip.partition(' ') = .sub(',', ' ').sub('=', ' ') for s in .split if s.start_with? '--' @long = s elsif s.start_with? '-' @short = s else @argcount = 1 end end if @argcount == 1 matched = description.scan(/\[default: (.*)\]/)[0] @value = matched ? matched[0] : nil end end |
Instance Attribute Details
#argcount ⇒ Object (readonly)
Returns the value of attribute argcount.
29 30 31 |
# File 'lib/pwqgen/docopt.rb', line 29 def argcount @argcount end |
#long ⇒ Object (readonly)
Returns the value of attribute long.
29 30 31 |
# File 'lib/pwqgen/docopt.rb', line 29 def long @long end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
29 30 31 |
# File 'lib/pwqgen/docopt.rb', line 29 def short @short end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
29 30 31 |
# File 'lib/pwqgen/docopt.rb', line 29 def value @value end |
Instance Method Details
#==(other) ⇒ Object
78 79 80 |
# File 'lib/pwqgen/docopt.rb', line 78 def == other self.inspect == other.inspect end |
#getopt ⇒ Object
70 71 72 |
# File 'lib/pwqgen/docopt.rb', line 70 def getopt [long, short, argcount].compact end |
#inspect ⇒ Object
74 75 76 |
# File 'lib/pwqgen/docopt.rb', line 74 def inspect "#<Docopt::Option short: #{short}, long: #{long}, argcount: #{argcount}, value: #{value}>" end |
#set_value(val) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/pwqgen/docopt.rb', line 52 def set_value val if argcount.zero? @value = true else @value = val end end |
#symbols ⇒ Object
64 65 66 67 68 |
# File 'lib/pwqgen/docopt.rb', line 64 def symbols [short, long].compact.map do |name| name.gsub(/^-+/, '').to_sym end end |
#synonyms ⇒ Object
60 61 62 |
# File 'lib/pwqgen/docopt.rb', line 60 def synonyms ([short, long] + symbols).compact end |