NotExpression.js 971 B

123456789101112131415161718192021222324252627282930313233343536
  1. var NotExpression = module.exports = (function(){
  2. // CONSTRUCTOR
  3. /**
  4. * An $not pipeline expression.
  5. *
  6. * @see evaluate
  7. **/
  8. var klass = function NotExpression(){
  9. if(arguments.length !== 0) throw new Error("zero args expected");
  10. base.call(this);
  11. }, base = require("./NaryExpression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  12. // DEPENDENCIES
  13. var Value = require("../Value");
  14. // PROTOTYPE MEMBERS
  15. proto.getOpName = function getOpName(){
  16. return "$not";
  17. };
  18. proto.addOperand = function addOperand(expr) {
  19. this.checkArgLimit(1);
  20. base.prototype.addOperand.call(this, expr);
  21. };
  22. /**
  23. * Returns the boolean opposite value passed to it. When passed a true value, $not returns false; when passed a false value, $not returns true.
  24. **/
  25. proto.evaluate = function evaluate(doc){
  26. this.checkArgCount(1);
  27. var op = this.operands[0].evaluate(doc);
  28. return !Value.coerceToBool(op);
  29. };
  30. return klass;
  31. })();