Class: MongoQL::Expression::Projection
- Inherits:
-
MongoQL::Expression
- Object
- MongoQL::Expression
- MongoQL::Expression::Projection
- Defined in:
- lib/mongo_ql/expression/projection.rb
Constant Summary
Constants inherited from MongoQL::Expression
Constants included from CollectionOperators
CollectionOperators::AGGREGATE_OPS
Constants included from UnaryOperators
Constants included from BinaryOperators
Instance Attribute Summary collapse
-
#expression ⇒ Object
Returns the value of attribute expression.
-
#field ⇒ Object
Returns the value of attribute field.
Instance Method Summary collapse
-
#initialize(field, expression = 1) ⇒ Projection
constructor
A new instance of Projection.
- #to_ast ⇒ Object
Methods inherited from MongoQL::Expression
#as_date, #if_null, #then, #type
Methods included from StringOperators
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
#expression ⇒ Object
Returns the value of attribute expression.
5 6 7 |
# File 'lib/mongo_ql/expression/projection.rb', line 5 def expression @expression end |
#field ⇒ Object
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_ast ⇒ Object
27 28 29 |
# File 'lib/mongo_ql/expression/projection.rb', line 27 def to_ast { field.to_s => expression } end |