Class: ScopedSearch::QueryLanguage::AST::OperatorNode
- Inherits:
-
Node
- Object
- Node
- ScopedSearch::QueryLanguage::AST::OperatorNode
- Defined in:
- lib/scoped_search/query_language/ast.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) children
readonly
Returns the value of attribute children.
-
- (Object) operator
readonly
Returns the value of attribute operator.
Instance Method Summary (collapse)
-
- (Object) [](child_nr)
Returns a child node by index, starting with 0.
-
- (Boolean) eql?(node)
:nodoc.
-
- (Boolean) infix?
Returns true if this is an infix operator.
-
- (OperatorNode) initialize(operator, children)
constructor
:nodoc.
-
- (Object) lhs
Return the left-hand side (LHS) operand for this operator.
-
- (Boolean) prefix?
Returns true if this is a prefix operator.
-
- (Object) rhs
Return the right-hand side (RHS) operand for this operator.
-
- (Object) simplify
Tree simplicication: returns itself after simpifying its children.
-
- (Object) to_a
Return an array representation for the node.
Methods inherited from Node
Constructor Details
- (OperatorNode) initialize(operator, children)
:nodoc
67 68 69 70 |
# File 'lib/scoped_search/query_language/ast.rb', line 67 def initialize(operator, children) # :nodoc @operator = operator @children = children end |
Instance Attribute Details
- (Object) children (readonly)
Returns the value of attribute children
65 66 67 |
# File 'lib/scoped_search/query_language/ast.rb', line 65 def children @children end |
- (Object) operator (readonly)
Returns the value of attribute operator
64 65 66 |
# File 'lib/scoped_search/query_language/ast.rb', line 64 def operator @operator end |
Instance Method Details
- (Object) [](child_nr)
Returns a child node by index, starting with 0.
111 112 113 |
# File 'lib/scoped_search/query_language/ast.rb', line 111 def [](child_nr) children[child_nr] end |
- (Boolean) eql?(node)
:nodoc
83 84 85 |
# File 'lib/scoped_search/query_language/ast.rb', line 83 def eql?(node) # :nodoc node.kind_of?(OperatorNode) && node.operator == operator && node.children.eql?(children) end |
- (Boolean) infix?
Returns true if this is an infix operator
101 102 103 |
# File 'lib/scoped_search/query_language/ast.rb', line 101 def infix? children.length > 1 end |
- (Object) lhs
Return the left-hand side (LHS) operand for this operator.
88 89 90 91 92 |
# File 'lib/scoped_search/query_language/ast.rb', line 88 def lhs raise ScopedSearch::Exception, "Operator does not have a LHS" if prefix? raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2 children[0] end |
- (Boolean) prefix?
Returns true if this is a prefix operator
106 107 108 |
# File 'lib/scoped_search/query_language/ast.rb', line 106 def prefix? children.length == 1 end |
- (Object) rhs
Return the right-hand side (RHS) operand for this operator.
95 96 97 98 |
# File 'lib/scoped_search/query_language/ast.rb', line 95 def rhs raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2 children.length == 1 ? children[0] : children[1] end |
- (Object) simplify
Tree simplicication: returns itself after simpifying its children
73 74 75 76 |
# File 'lib/scoped_search/query_language/ast.rb', line 73 def simplify @children = children.map { |c| c.simplify } return self end |
- (Object) to_a
Return an array representation for the node
79 80 81 |
# File 'lib/scoped_search/query_language/ast.rb', line 79 def to_a [@operator] + @children.map { |c| c.to_a } end |