module ScopedSearch::QueryLanguage::AST

Public Class Methods

from_array(arg) click to toggle source

Constructs an AST from an array notation.

# File lib/scoped_search/query_language/ast.rb, line 4
def self.from_array(arg)
  if arg.kind_of?(Array)
    operator = arg.shift
    case operator
    when :and, :or
      LogicalOperatorNode.new(operator, arg.map { |c| from_array(c) })
    when Symbol
      OperatorNode.new(operator, arg.map { |c| from_array(c) })
    else
      raise ScopedSearch::Exception, "Not a valid array representation of an AST!"
    end
  else
    return LeafNode.new(arg)
  end
end