Class: MongoQL::Expression::Projection

Inherits:
MongoQL::Expression show all
Defined in:
lib/mongo_ql/expression/projection.rb

Constant Summary

Constants inherited from MongoQL::Expression

FORMATING_OPS

Constants included from CollectionOperators

CollectionOperators::AGGREGATE_OPS

Constants included from UnaryOperators

UnaryOperators::UNARY_OPS

Constants included from BinaryOperators

BinaryOperators::BINARY_OPS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MongoQL::Expression

#as_date, #if_null, #then, #type

Methods included from StringOperators

#concat, #substr, #trim

Methods included from CollectionOperators

#any?, #concat_arrays, #contains, #filter, #map, #reduce

Constructor Details

#initialize(field, expression = 1) ⇒ Projection

Returns a new instance of Projection.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mongo_ql/expression/projection.rb', line 7

def initialize(field, expression = 1)
  @expression = case expression
                when 0, 1
                  expression
                when Expression::FieldNode
                  expression
                else
                  raise ArgumentError, "#{expression&.inspect} is not a valid project expression"
                end

  @field = case field
           when String, Symbol
             Expression::FieldNode.new(field)
           when Expression::FieldNode
             field
           else
             raise ArgumentError, "#{field&.inspect} is not a valid project field"
           end
end

Instance Attribute Details

#expressionObject

Returns the value of attribute expression.



5
6
7
# File 'lib/mongo_ql/expression/projection.rb', line 5

def expression
  @expression
end

#fieldObject

Returns the value of attribute field.



5
6
7
# File 'lib/mongo_ql/expression/projection.rb', line 5

def field
  @field
end

Instance Method Details

#to_astObject



27
28
29
# File 'lib/mongo_ql/expression/projection.rb', line 27

def to_ast
  { field.to_s => expression }
end