Skip to content

Commit

Permalink
A postImportTableFunction can be defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Léo Frachet committed Mar 9, 2018
1 parent 9407ece commit 8cb54fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions gtfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ class Gtfs {
*
* Optional ad-hoc boolean. Default is true. Will force the parser to ignore invalid rows in the tables.
*
*
* # options.postImportTableFunction
*
* Optional ad-hoc function which will be applied on every item of every table after importation.
*
*
* # options.forcedSchema
*
* Will overwrite the default schema by the value passed.
Expand All @@ -179,6 +185,7 @@ class Gtfs {
* @param {{
* regexPatternObjectsByTableName: Map.<string, Array.<{regex: RegExp, pattern: string}>>,
* throws: boolean,
* postImportTableFunction: function,
* forcedSchema,
* }} [options] Optional. See list above.
* @return {Gtfs} gtfs Instanciated GTFS object.
Expand Down
11 changes: 7 additions & 4 deletions helpers/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ exports.importTable = (gtfs, tableName) => {
const rows = getRows(fileContent, gtfs._regexPatternObjectsByTableName.get(tableName), tableName);

gtfs._tables.set(tableName, processRows(gtfs, tableName, indexKeys, rows, gtfs._shouldThrow));
return;
}
} else {
infoLog(`Empty table will be set for table ${tableName} (no input file at path ${gtfs._path}).`);

infoLog(`Empty table will be set for table ${tableName} (no input file at path ${gtfs._path}).`);
gtfs._tables.set(tableName, new Map());
}

gtfs._tables.set(tableName, new Map());
if (gtfs._postImportTableFunction) {
gtfs.forEachItemInTable(tableName, gtfs._postImportTableFunction);
}
};

/**
Expand Down

0 comments on commit 8cb54fc

Please sign in to comment.