Class ScopedSearch::QueryLanguage::AST::OperatorNode
In: lib/scoped_search/query_language/ast.rb
Parent: Node

AST class for representing operators in the query. An operator node has an operator and operands that are represented as AST child nodes. Usually, operator nodes have one or two children. For logical operators, a distinct subclass exists to implement some tree simplification rules.

Methods

[]   eql?   infix?   lhs   new   prefix?   rhs   simplify   to_a  

Attributes

children  [R] 
operator  [R] 

Public Class methods

[Source]

    # File lib/scoped_search/query_language/ast.rb, line 67
67:     def initialize(operator, children) # :nodoc
68:       @operator = operator
69:       @children = children
70:     end

Public Instance methods

Returns a child node by index, starting with 0.

[Source]

     # File lib/scoped_search/query_language/ast.rb, line 111
111:     def [](child_nr)
112:       children[child_nr]
113:     end

[Source]

    # File lib/scoped_search/query_language/ast.rb, line 83
83:     def eql?(node) # :nodoc
84:       node.kind_of?(OperatorNode) && node.operator == operator && node.children.eql?(children)
85:     end

Returns true if this is an infix operator

[Source]

     # File lib/scoped_search/query_language/ast.rb, line 101
101:     def infix?
102:       children.length > 1
103:     end

Return the left-hand side (LHS) operand for this operator.

[Source]

    # File lib/scoped_search/query_language/ast.rb, line 88
88:     def lhs
89:       raise ScopedSearch::Exception, "Operator does not have a LHS" if prefix?
90:       raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2
91:       children[0]
92:     end

Returns true if this is a prefix operator

[Source]

     # File lib/scoped_search/query_language/ast.rb, line 106
106:     def prefix?
107:       children.length == 1
108:     end

Return the right-hand side (RHS) operand for this operator.

[Source]

    # File lib/scoped_search/query_language/ast.rb, line 95
95:     def rhs
96:       raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2
97:       children.length == 1 ? children[0] : children[1]
98:     end

Tree simplicication: returns itself after simpifying its children

[Source]

    # File lib/scoped_search/query_language/ast.rb, line 73
73:     def simplify
74:       @children = children.map { |c| c.simplify }
75:       return self
76:     end

Return an array representation for the node

[Source]

    # File lib/scoped_search/query_language/ast.rb, line 79
79:     def to_a
80:       [@operator] + @children.map { |c| c.to_a }
81:     end

[Validate]