Source: provider/convention/filterProviderByMap.js

  1. /**
  2. * @author Sloan Seaman
  3. * @copyright 2016 and on
  4. * @version .1
  5. * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  6. */
  7. /** @private */
  8. var AbstractProviderByMap = require('../abstractProviderByMap.js');
  9. /**
  10. * Uses the passed in map to provide Filters.
  11. *
  12. * The Map should contain two keys: 'pre' and 'post'. The values of each should be
  13. * the an array of {@link Filter} objects.
  14. *
  15. * WARNING: At this time this object has not been tested in the SkillVC system and exists as a "ToDo"
  16. *
  17. * @constructor
  18. * @implements {Provider}
  19. * @implements {ItemProcessor}
  20. * @see {@link AbstractProviderByMap}
  21. * @param {Map} map The object structure of the raw Filters to use.
  22. * @param {Object.<String, Object>} options Options for processing. See {@link AbstractProviderByMap}
  23. */
  24. function FilterProviderByMap(map, options) {
  25. this._map = map;
  26. AbstractProviderByMap.apply(this, [
  27. this._map,
  28. options]);
  29. }
  30. FilterProviderByMap.prototype = Object.create(AbstractProviderByMap.prototype);
  31. FilterProviderByMap.prototype.constructor = FilterProviderByMap;
  32. /**
  33. *
  34. *
  35. * @function
  36. * @param {Map} items Mapof the items being processed
  37. * @param {String} itemId The Id of the item to process
  38. * @param {Object} map The map being processed
  39. * @param {Object} options Any options that are being passed to the ItemProcessor (can be null)
  40. */
  41. FilterProviderByMap.prototype.processItem = function(items, itemId, map, options) {
  42. /*eslint no-unused-vars: ["error", { "args": "none" }]*/
  43. items[itemId] = map[itemId];
  44. };
  45. /**
  46. *
  47. *
  48. * @function
  49. * @param {Map} items Map of the items being processed
  50. * @param {Object} map The map being processed
  51. * @param {Object} options Any options that are being passed to the ItemProcessor (can be null)\
  52. */
  53. FilterProviderByMap.prototype.processItems = function(items, map, options) {
  54. /*eslint no-unused-vars: ["error", { "args": "none" }]*/
  55. for (var key in map) {
  56. items[key] = map[key];
  57. }
  58. };
  59. /**
  60. * Returns all the pre filters (filters that implement executePre())
  61. *
  62. * @return {Array.Filter} Array of all the loaded pre filters
  63. */
  64. FilterProviderByMap.prototype.getPreFilters = function() {
  65. return this._map.pre;
  66. };
  67. /**
  68. * Returns all the post filters (filters that implement executePost())
  69. *
  70. * @return {Array.Filter} Array of all the loaded post filters
  71. */
  72. FilterProviderByMap.prototype.getPostFilters = function() {
  73. return this._map.post;
  74. };
  75. module.exports = FilterProviderByMap;