Class: Raph::Parser::GroupedArgParser
- Inherits:
-
BaseParser
- Object
- BaseParser
- Raph::Parser::GroupedArgParser
- Defined in:
- lib/raph/parser/grouped_arg_parser.rb
Overview
Grouped arguments are arguments that follows a group - a specific argument. In other words flags and assignments represents groups and arguments followed them are grouped arguments.
Next example:
'--group1', '1', '2', '--group2', 'three'
has two groups (:group1 and :group2) with
corresponding grouped arguments (['1', '2'], ['three'])
Instance Method Summary collapse
- #group?(arg) ⇒ Boolean
-
#initialize ⇒ GroupedArgParser
constructor
A new instance of GroupedArgParser.
- #parse(args) ⇒ Object
Methods inherited from BaseParser
Constructor Details
#initialize ⇒ GroupedArgParser
Returns a new instance of GroupedArgParser.
17 18 19 20 |
# File 'lib/raph/parser/grouped_arg_parser.rb', line 17 def initialize @flag_parser = FlagParser.new @assignment_parser = AssignmentParser.new end |
Instance Method Details
#group?(arg) ⇒ Boolean
37 38 39 |
# File 'lib/raph/parser/grouped_arg_parser.rb', line 37 def group?(arg) @flag_parser.flag?(arg) || @assignment_parser.assignment?(arg) end |
#parse(args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/raph/parser/grouped_arg_parser.rb', line 22 def parse(args) groups = {} current_group = nil args.each do |arg| if group? arg current_group = to_underscored_sym arg groups[current_group] = [] else groups[current_group].push(arg) if current_group end end groups end |