class Raph::Parser::GroupedArgParser

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’])

Public Class Methods

new() click to toggle source
# File lib/raph/parser/grouped_arg_parser.rb, line 17
def initialize
  @flag_parser = FlagParser.new
  @assignment_parser = AssignmentParser.new
end

Public Instance Methods

group?(arg) click to toggle source
# File lib/raph/parser/grouped_arg_parser.rb, line 37
def group?(arg)
  @flag_parser.flag?(arg) || @assignment_parser.assignment?(arg)
end
parse(args) click to toggle source
# 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