Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

checkValidCodes

smidget edited this page Jul 20, 2012 · 2 revisions

Purpose

This function will check a variable's arguments for typos.

Parameters

Primary Variable (String of variable name or RVariable)

This is the variable that will be checked for typos.

Dump file (String or File)

Whether or not we want to dump the results of this output to a file or simply print them to the console. If this is set to a string, it will create a file and use that. If a file already exists in that place, it will append to it rather than overwriting it.

A file pointer can also be passed here and that will be used instead of opening a new file pointer.

If you do not want to use a dump file, simply pass a blank string ("") as the parameter.

Argument/Valid code pairs* (String, Array of Strings pairs)

These parameters are given in the form of argument name/valid codes pairs. The syntax for this is slightly confusing. See example below for a concrete example.

The idea is to first pass a string that is the name of an argument. For example, if we had an argument called "reachhand" that had valid codes of "l", "r", "b", or "n" (representing left, right, both hands, and no reach, respectively), we would pass two arguments like this: "reachhand", ["l", "r", "b", "n"]. Note that the second parameter is inside of square brackets [], this denotes a Ruby Array.

See below for examples.

Returns

Nothing.

Examples

# We want to check the codes on an argument called reachhand in the trial variable.
# Valid codes for this argument are "l", "r", "b", and "n". We also want to check
# codes on another argument called headturn, and valid codes are "y" and "n".

# First get string to path of the output file we want to save to.
output_file = File.expand_path("~/Desktop/output.txt")

# Now check the codes
checkValidCodes("trial", output_file, "reachhand", ["l", "r", "n", "b"], "headturn", ["y", "n"])