Class DataMap
A DataMap specifies a conversion from a Record object into some other type of object. An external file is used to specify how the conversion is accomplished. This external file is in CSV format, with the first column being the name of the attribute in the target object. The second column is then the attribute in the Record object that will be plugged into the target object. The Record attribute references can be complex, for example they can specify array elements, nested attributes, and so forth.
In most cases, the conversion will be between a Record object and an Event object. The template
will load the default maps automatically; you will only need to use this class if you are
creating your own output objects or providing multiple conversions.
Defined in: utils.js.
Constructor Attributes | Constructor Name and Description |
---|---|
DataMap(fileName, nosafe)
Creates a DataMap object by loading the map from a CSV file on disk.
|
Method Attributes | Method Name and Description |
---|---|
compile()
DataMap objects are normally used to convert one object type into another, and the convert()
routine typically uses an eval() to accomplish this.
|
|
extend(fileName, nosafe)
This method extends an existing DataMap by adding additional mapped fields.
|
|
makesafe()
Most DataMaps are simple translations between one flat object and another, but in some cases
the source object may be a more complex object.
|
Example:
// First, define the conversion in an external file (CSV format) Rec2Evt.map: Message,msg InitUserName,iun ... // Next, load the DataMap: this.MAPS.Rec2Evt = new DataMap(this.CONFIG.collDir + "/Rec2Evt.map"); // And set your values in the Record object (typically in Record.parse()) rec.msg = rec.s_RXBufferString.substr(0,20); rec.iun = rec.s_RXBufferString.substr(21,25); // Finally, run the conversion: rec.convert(this, instance.MAPS.Rec2Evt);
- Parameters:
- {String} fileName
- The file to load the DataMap from
- {Boolean} nosafe
- A flag to inhibit making the map "safe" - e.g. escaping complex attribute references and pre-compiling the map - use for Evt2EvtData, which is not used as a normal DataMap
- Parameters:
- {String} fileName
- The name of the file that contains the DataMap extension definition.
- {Boolean} nosafe
- A flag to inhibit making the map "safe" - e.g. escaping complex attribute references and pre-compiling the map - use for Evt2EvtData, which is not used as a normal DataMap