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:
- String: The parser will search for this string at the beginning of each line and treat that line as the header.
- Number: The parser will use this line number as the header row.
Defined in: utils.js.
Constructor Attributes | Constructor Name and Description |
---|---|
KeyMap(fileName, hdrID)
Creates a KeyMap object that loads the map from a CSV file on disk.
|
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.
|
|
refresh()
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)
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:
- String: Assumes that the KeyMap includes a header row with text column names. Returns the string value of the column with that name.
- Number: Returns the string value of of the selected column.
- 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.