MatchDetails.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. "use strict";
  2. /**
  3. * MatchDetails
  4. * @class MatchDetails
  5. * @namespace mungedb-aggregate.pipeline.matcher
  6. * @module mungedb-aggregate
  7. * @constructor
  8. **/
  9. var MatchDetails = module.exports = function (){
  10. this._elemMatchKeyRequested = false;
  11. this.resetOutput();
  12. }, klass = MatchDetails, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  13. proto._elemMatchKey = undefined;
  14. proto._elemMatchKeyRequested = undefined;
  15. proto._loadedRecord = undefined;
  16. /**
  17. *
  18. * Set _loadedRecord to false and _elemMatchKey to undefined
  19. * @method resetOutput
  20. *
  21. */
  22. proto.resetOutput = function resetOutput(){
  23. this._loadedRecord = false;
  24. this._elemMatchKey = undefined;
  25. };
  26. /**
  27. *
  28. * Return a string representation of ourselves
  29. * @method toString
  30. *
  31. */
  32. proto.toString = function toString(){
  33. return "loadedRecord: " + this._loadedRecord + " " + "elemMatchKeyRequested: " + this._elemMatchKeyRequested + " " + "elemMatchKey: " + ( this._elemMatchKey ? this._elemMatchKey : "NONE" ) + " ";
  34. };
  35. /**
  36. *
  37. * Set the _loadedRecord property
  38. * @method setLoadedRecord
  39. * @param loadedRecord
  40. *
  41. */
  42. proto.setLoadedRecord = function setLoadedRecord(loadedRecord){
  43. this._loadedRecord = loadedRecord;
  44. };
  45. /**
  46. *
  47. * Return the _loadedRecord property
  48. * @method hasLoadedRecord
  49. *
  50. */
  51. proto.hasLoadedRecord = function hasLoadedRecord(){
  52. return this._loadedRecord;
  53. };
  54. /**
  55. *
  56. * Return the _elemMatchKeyRequested property
  57. * @method needRecord
  58. *
  59. */
  60. proto.needRecord = function needRecord(){
  61. return this._elemMatchKeyRequested;
  62. };
  63. /**
  64. *
  65. * Set the _elemMatchKeyRequested property to true
  66. * @method requestElemMatchKey
  67. *
  68. */
  69. proto.requestElemMatchKey = function requestElemMatchKey(){
  70. this._elemMatchKeyRequested = true;
  71. };
  72. /**
  73. *
  74. * Return the _elemMatchKey property so we can check if exists
  75. * @method hasElemMatchKey
  76. *
  77. */
  78. proto.hasElemMatchKey = function hasElemMatchKey(){
  79. return (typeof this._elemMatchKey !== 'undefined');
  80. };
  81. /**
  82. *
  83. * Return the _elemMatchKey property
  84. * @method elemMatchKey
  85. *
  86. */
  87. proto.elemMatchKey = function elemMatchKey(){
  88. if (!this.hasElemMatchKey()) throw new Error("no elem match key MatchDetails:29");
  89. return this._elemMatchKey;
  90. };
  91. /**
  92. *
  93. * If we request an _elemMatchKey then set it to the input
  94. * @method setElemMatchKey
  95. * @param elemMatchKey
  96. *
  97. */
  98. proto.setElemMatchKey = function setElemMatchKey(elemMatchKey){
  99. if ( this._elemMatchKeyRequested ) {
  100. this._elemMatchKey = elemMatchKey;
  101. }
  102. };