Class Index | File Index

Classes


Class KeyMap

A KeyMap defines a relationship between a key and a set of strings related to that key. Each KeyMap is loaded from an input file (CSV format) and can then be used as a reference source to enhance data gathered by the Collector. For example, you could use the user's name to pull back the phone number, e-mail address, and other details relating to that user. The second parameter enable optional header-row parsing; you pass in an ID to tell the constructor how to find the header row. If you pass in:

Note that lines before the header row will be ignored.
Defined in: utils.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
KeyMap(fileName, hdrID)
Creates a KeyMap object that loads the map from a CSV file on disk.
Method Summary
Method Attributes Method Name and Description
 
extend(fileName, hdrID)
This method extends an existing KeyMap by adding additional keys and values.
 
lookup(key, col)
Looks up a set of values in a KeyMap with this string as the key.
 
Checks the KeyMap source file to see if it has been modified, and reloads it if so.
Class Detail
KeyMap(fileName, hdrID)
Creates a KeyMap object that loads the map from a CSV file on disk.

Example:

// First, define your KeyMap input file in CSV format, with the key in the first column
usermap.map:
user1,user1@novell.com,801-861-1000
user2,user2@novell.com,801-861-2000
// Next, load the KeyMap
instance.MAPS.userMap = new KeyMap( instance.CONFIG.collDir + "/usermap.map");
// And then do your lookups:
var userinfo = instance.MAPS.userMap.lookup(rec.username);
rec.useremail = userinfo[0];
rec.userphone = userinfo[1];
// (or you could just put the array references directly in Rec2Evt.map)
Parameters:
{String} fileName
The name of the file that contains the KeyMap definition.
{String or Number} hdrID
Tells the constructor how to identify the header row.
Method Detail
extend(fileName, hdrID)
This method extends an existing KeyMap by adding additional keys and values. The source file must be in the standard CSV format of the original KeyMap file. A hdrId argument is provided as with the constructor, however this header is just skipped and the original header will be used to determine column placement (as a result, the columns must be in the same order). Note also that if identical keys are specified in the new input map, they will replace existing entries.
Parameters:
{String} fileName
The name of the file that contains the KeyMap extension definition.
{String or Number} hdrID
Tells the constructor how to identify the header row.

{String[], String} lookup(key, col)
Looks up a set of values in a KeyMap with this string as the key. A KeyMap is used to associate a set of values with a lookup key, sort of like a hash map, but with multiple possible return strings. You can either fetch the entire array of results, or select a single column to return with the "col" parameter. If you pass in "col" as: Note that the return type depends on whether you use "col" or not; either you get a String back or an Array of Strings.
Parameters:
{String} key
The string key to use for the lookup, it must match a string in the first column of the KeyMap
{Number or String} col
Optional, specifies a single column to return (as array 0).
Returns:
{String[]} An array of strings that were associated with this key in the KeyMap. Null if no match.
{String}

refresh()
Checks the KeyMap source file to see if it has been modified, and reloads it if so.

©2008
Documentation generated by JsDoc Toolkit 2.0.2 on Thu Oct 07 2010 07:23:17 GMT-0400 (EDT)