Class: Cyrel::Expression::Operator

Inherits:
Base
  • Object
show all
Defined in:
lib/cyrel/expression/operator.rb

Overview

Represents a binary arithmetic operation (e.g., +, -, *, /, %, ^).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#!=, #%, #&, #*, #+, #-, #/, #<, #<=, #==, #=~, #>, #>=, #^, #|

Constructor Details

#initialize(left, operator, right) ⇒ Operator

Returns a new instance of Operator.

Parameters:



12
13
14
15
16
# File 'lib/cyrel/expression/operator.rb', line 12

def initialize(left, operator, right)
  @left = Expression.coerce(left) # Ensure operands are Expression objects
  @operator = operator
  @right = Expression.coerce(right)
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



7
8
9
# File 'lib/cyrel/expression/operator.rb', line 7

def left
  @left
end

#operatorObject (readonly)

Returns the value of attribute operator.



7
8
9
# File 'lib/cyrel/expression/operator.rb', line 7

def operator
  @operator
end

#rightObject (readonly)

Returns the value of attribute right.



7
8
9
# File 'lib/cyrel/expression/operator.rb', line 7

def right
  @right
end

Instance Method Details

#render(query) ⇒ String

Renders the operator expression.

Parameters:

  • query (Cyrel::Query)

    The query object for rendering operands.

Returns:

  • (String)

    The Cypher string fragment (e.g., “(n.age + $p1)”).



21
22
23
24
# File 'lib/cyrel/expression/operator.rb', line 21

def render(query)
  # Parentheses ensure correct precedence
  "(#{@left.render(query)} #{@operator} #{@right.render(query)})"
end