Skip to content

Commit

Permalink
Add documentation of the getters
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoFrachet committed Jan 15, 2018
1 parent b307c0d commit af8b536
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions helpers/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

const schema = require('./schema');

/**
* Get the grand parent item using one of its child.
*
* @param {Object} itemWithForeignIndexId The child item.
* @param {string} parentTableName The name of the table containing the parent item.
* @param {string} grandParentTableName The name of the table containing the grand parent item.
* @param {Gtfs} gtfs The GTFS containing the parent item
* @return {Object} The grand parent item.
*/
function getGrandParentItem(itemWithForeignIndexId, parentTableName, grandParentTableName, gtfs) {
if (
itemWithForeignIndexId === undefined ||
Expand Down Expand Up @@ -40,6 +49,14 @@ function getGrandParentItem(itemWithForeignIndexId, parentTableName, grandParent
return gtfs.getItemWithIndexInTable(parentItem[grandParentIndexKey], grandParentTableName);
}

/**
* Get the child items of an item.
*
* @param {Object} parentItem The parent item.
* @param {string} tableName The name of the table containing the child items.
* @param {Gtfs} gtfs The GTFS containing the child items.
* @return {Map.<string, Object>} Indexed child items.
*/
function getIndexedItemsWithParent(parentItem, tableName, gtfs) {
if (schema.deepnessByTableName[tableName] !== 2) {
throw new Error(`Table "${tableName}" is not of deepness 2.`);
Expand All @@ -59,6 +76,14 @@ function getIndexedItemsWithParent(parentItem, tableName, gtfs) {
return indexedTable.get(parentItem[firstIndexKey]);
}

/**
* Get the child items of an item using its index.
*
* @param {Object} parentIndex The parent item's index.
* @param {string} tableName The name of the table containing the child items.
* @param {Gtfs} gtfs The GTFS containing the child items.
* @return {Map.<string, Object>} Indexed child items.
*/
function getIndexedItemsWithParentIndex(parentIndex, tableName, gtfs) {
if (schema.deepnessByTableName[tableName] !== 2) {
throw new Error(`Table "${tableName}" is not of deepness 2.`);
Expand Down Expand Up @@ -122,6 +147,14 @@ function getItemWithIndexes(firstIndex, secondIndex, tableName, gtfs) {
return (indexedTable.has(firstIndex)) ? indexedTable.get(firstIndex).get(secondIndex) : null;
}

/**
* Get the parent item using one of its child.
*
* @param {Object} itemWithForeignIndexId The child item.
* @param {string} tableName The name of the table containing the parent item.
* @param {Gtfs} gtfs The GTFS containing the parent item
* @return {Object} The parent item.
*/
function getParentItem(itemWithForeignIndexId, tableName, gtfs) {
if (
itemWithForeignIndexId === undefined ||
Expand Down

0 comments on commit af8b536

Please sign in to comment.