MatchDetails.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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, proto = klass.prototype;
  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 + " " +
  34. "elemMatchKeyRequested: " + this._elemMatchKeyRequested + " " +
  35. "elemMatchKey: " + ( this._elemMatchKey ? this._elemMatchKey : "NONE" ) + " ";
  36. };
  37. /**
  38. *
  39. * Set the _loadedRecord property
  40. * @method setLoadedRecord
  41. * @param loadedRecord
  42. *
  43. */
  44. proto.setLoadedRecord = function setLoadedRecord(loadedRecord){
  45. this._loadedRecord = loadedRecord;
  46. };
  47. /**
  48. *
  49. * Return the _loadedRecord property
  50. * @method hasLoadedRecord
  51. *
  52. */
  53. proto.hasLoadedRecord = function hasLoadedRecord(){
  54. return this._loadedRecord;
  55. };
  56. /**
  57. *
  58. * Return the _elemMatchKeyRequested property
  59. * @method needRecord
  60. *
  61. */
  62. proto.needRecord = function needRecord(){
  63. return this._elemMatchKeyRequested;
  64. };
  65. /**
  66. *
  67. * Set the _elemMatchKeyRequested property to true
  68. * @method requestElemMatchKey
  69. *
  70. */
  71. proto.requestElemMatchKey = function requestElemMatchKey(){
  72. this._elemMatchKeyRequested = true;
  73. };
  74. /**
  75. *
  76. * Return the _elemMatchKey property so we can check if exists
  77. * @method hasElemMatchKey
  78. *
  79. */
  80. proto.hasElemMatchKey = function hasElemMatchKey(){
  81. return (typeof this._elemMatchKey !== "undefined");
  82. };
  83. /**
  84. *
  85. * Return the _elemMatchKey property
  86. * @method elemMatchKey
  87. *
  88. */
  89. proto.elemMatchKey = function elemMatchKey(){
  90. if (!this.hasElemMatchKey()) throw new Error("no elem match key MatchDetails:29");
  91. return this._elemMatchKey;
  92. };
  93. /**
  94. *
  95. * If we request an _elemMatchKey then set it to the input
  96. * @method setElemMatchKey
  97. * @param elemMatchKey
  98. *
  99. */
  100. proto.setElemMatchKey = function setElemMatchKey(elemMatchKey){
  101. if ( this._elemMatchKeyRequested ) {
  102. this._elemMatchKey = elemMatchKey;
  103. }
  104. };