Class: Pablo::Option
- Includes:
- Helpers
- Defined in:
- lib/pablo/option.rb
Instance Attribute Summary
Attributes inherited from Parser
#desc, #last_match, #longdesc, #names, #usage
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Option
constructor
A new instance of Option.
-
#names_to_rex ⇒ Object
Format an option’s names to be used in a Regexp.
-
#names_to_user ⇒ Object
Format an option’s names to be displayed to the user.
- #parse(args) ⇒ Object
Methods inherited from Parser
Constructor Details
#initialize(*args, &block) ⇒ Option
Returns a new instance of Option.
30 31 32 |
# File 'lib/pablo/option.rb', line 30 def initialize *args, &block super(*args, &block) end |
Instance Method Details
#names_to_rex ⇒ Object
Format an option’s names to be used in a Regexp
68 69 70 |
# File 'lib/pablo/option.rb', line 68 def names_to_rex Regexp.new(@names.collect { |n| format(n) }.join('|')) end |
#names_to_user ⇒ Object
Format an option’s names to be displayed to the user.
62 63 64 |
# File 'lib/pablo/option.rb', line 62 def names_to_user @names.collect { |n| format(n) }.join('|') end |
#parse(args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pablo/option.rb', line 34 def parse args name = nil idx = args.zip((0...args.length).to_a).find_index { |(a,i)| verifies?(a,i) and (name = matches?(a)) } unless idx.nil? args.consume idx args.slice idx unless @opts[:negates].nil? @pablo.[@opts[:negates].to_sym] = false else @pablo.[name] = true end consume?(name, args) run?(args) args.unslice true else false end end |