Method: OpenC3::ConfigParser#verify_num_parameters

Defined in:
lib/openc3/config/config_parser.rb

#verify_num_parameters(min_num_params, max_num_params, usage = "") ⇒ Object

Verifies the parameters in the config parameter have the specified number of parameter and raises an Error if not.

Parameters:

  • The minimum number of parameters

  • The maximum number of parameters. Pass nil to indicate there is no maximum number of parameters.



234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/openc3/config/config_parser.rb', line 234

def verify_num_parameters(min_num_params, max_num_params, usage = "")
  # This syntax works with 0 because each doesn't return any values
  # for a backwards range
  (1..min_num_params).each do |index|
    # If the parameter is nil (0 based) then we have a problem
    if @parameters[index - 1].nil?
      raise Error.new(self, "Not enough parameters for #{@keyword}.", usage, @url)
    end
  end
  # If they pass nil for max_params we don't check for a maximum number
  if max_num_params && !@parameters[max_num_params].nil?
    raise Error.new(self, "Too many parameters for #{@keyword}.", usage, @url)
  end
end