OrMatchExpression.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. var ListOfMatchExpression = require("./ListOfMatchExpression");
  3. var OrMatchExpression = module.exports = function OrMatchExpression (){
  4. base.call(this);
  5. this._expressions = [];
  6. this._matchType = "OR";
  7. }, klass = OrMatchExpression, base = ListOfMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}}); //jshint ignore:line
  8. /**
  9. *
  10. * Writes a debug string for this object
  11. * @method debugString
  12. * @param level
  13. *
  14. */
  15. proto.debugString = function debugString(level) {
  16. return this._debugAddSpace(level) +
  17. "$or\n" +
  18. this._debugList(level);
  19. };
  20. /**
  21. *
  22. * matches checks the input doc against the internal element path to see if it is a match
  23. * @method matches
  24. * @param doc
  25. * @param details
  26. *
  27. */
  28. proto.matches = function matches(doc,details) {
  29. for (var i = 0; i < this.numChildren(); i++) {
  30. if (this.getChild(i).matches( doc, null ) ){
  31. return true;
  32. }
  33. }
  34. return false;
  35. };
  36. /**
  37. *
  38. * Check if the input element matches
  39. * @method matchesSingleElement
  40. * @param e
  41. *
  42. */
  43. proto.matchesSingleElement = function matchesSingleElement(e) {
  44. for (var i = 0; i < this.numChildren(); i++) {
  45. if( this.getChild(i).matchesSingleElement(e) ) {
  46. return true;
  47. }
  48. }
  49. return false;
  50. };
  51. /**
  52. *
  53. * clone this instance to a new one
  54. * @method shallowClone
  55. *
  56. */
  57. proto.shallowClone = function shallowClone(){
  58. var clone = new OrMatchExpression();
  59. for (var i = 0; i < this.numChildren(); i++) {
  60. clone.add(this.getChild(i).shallowClone());
  61. }
  62. if (this.getTag()) {
  63. clone.setTag(this.getTag().clone());
  64. }
  65. return clone;
  66. };