Class: MongoQL::Expression::ValueNode
- Inherits:
-
MongoQL::Expression
- Object
- MongoQL::Expression
- MongoQL::Expression::ValueNode
- Defined in:
- lib/mongo_ql/expression/value_node.rb
Constant Summary collapse
- SUPPORTED_TYPES =
[ String, Integer, Float, Array, Hash, TrueClass, FalseClass, Date, DateTime, Symbol, MongoQL::Expression::ValueNode ].freeze
Constants inherited from MongoQL::Expression
Constants included from CollectionOperators
CollectionOperators::AGGREGATE_OPS
Constants included from UnaryOperators
Constants included from BinaryOperators
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #convert_to_date_if_possible ⇒ Object
-
#initialize(val) ⇒ ValueNode
constructor
A new instance of ValueNode.
- #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(val) ⇒ ValueNode
Returns a new instance of ValueNode.
14 15 16 17 18 |
# File 'lib/mongo_ql/expression/value_node.rb', line 14 def initialize(val) Expression::ValueNode.valid!(val) @value = val convert_to_date_if_possible end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
12 13 14 |
# File 'lib/mongo_ql/expression/value_node.rb', line 12 def value @value end |
Class Method Details
.valid!(value) ⇒ Object
42 43 44 45 46 |
# File 'lib/mongo_ql/expression/value_node.rb', line 42 def self.valid!(value) unless value.nil? || valid?(value) raise InvalidValueExpression, "#{value} must be in type #{SUPPORTED_TYPES.map(&:name).join(",")}" end end |
.valid?(value) ⇒ Boolean
38 39 40 |
# File 'lib/mongo_ql/expression/value_node.rb', line 38 def self.valid?(value) SUPPORTED_TYPES.any? { |type| value.is_a?(type) } end |
Instance Method Details
#convert_to_date_if_possible ⇒ Object
32 33 34 35 36 |
# File 'lib/mongo_ql/expression/value_node.rb', line 32 def convert_to_date_if_possible self.value = DateTime.iso8601(value) rescue => _ value end |
#to_ast ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mongo_ql/expression/value_node.rb', line 20 def to_ast case value when Date, DateTime # Expression::ValueNode.new(value.iso8601).to_date.to_ast { "$toDate" => value.iso8601 } when MongoQL::Expression::ValueNode value.to_ast else value end end |