class ScopedSearch::QueryLanguage::AST::OperatorNode
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.
Attributes
Public Class Methods
Source
# File lib/scoped_search/query_language/ast.rb 71 def initialize(operator, children, root_node = false) # :nodoc 72 @operator = operator 73 @children = children 74 75 raise ScopedSearch::QueryNotSupported, "Empty list of operands" if @children.empty? && !root_node 76 end
Public Instance Methods
Source
# File lib/scoped_search/query_language/ast.rb 121 def [](child_nr) 122 children[child_nr] 123 end
Returns a child node by index, starting with 0.
Source
# File lib/scoped_search/query_language/ast.rb 106 def empty? 107 children.length == 0 108 end
Source
# File lib/scoped_search/query_language/ast.rb 89 def eql?(node) # :nodoc 90 node.kind_of?(OperatorNode) && node.operator == operator && node.children.eql?(children) 91 end
Source
# File lib/scoped_search/query_language/ast.rb 111 def infix? 112 children.length > 1 113 end
Returns true if this is an infix operator
Source
# File lib/scoped_search/query_language/ast.rb 94 def lhs 95 raise ScopedSearch::Exception, "Operator does not have a LHS" if prefix? 96 raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2 97 children[0] 98 end
Return the left-hand side (LHS) operand for this operator.
Source
# File lib/scoped_search/query_language/ast.rb 116 def prefix? 117 children.length == 1 118 end
Returns true if this is a prefix operator
Source
# File lib/scoped_search/query_language/ast.rb 101 def rhs 102 raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2 103 children.length == 1 ? children[0] : children[1] 104 end
Return the right-hand side (RHS) operand for this operator.
Source
# File lib/scoped_search/query_language/ast.rb 79 def simplify 80 @children = children.map { |c| c.simplify } 81 return self 82 end
Tree simplicication: returns itself after simpifying its children
Source
# File lib/scoped_search/query_language/ast.rb 85 def to_a 86 [@operator] + @children.map { |c| c.to_a } 87 end
Return an array representation for the node