Class: Cyrel::Expression::PatternComprehension

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

Overview

Represents a Pattern Comprehension in Cypher. Syntax: [ pattern WHERE condition | expression ] Simplified version for now: [ pattern | expression ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(pattern, projection_expression) ⇒ PatternComprehension

Returns a new instance of PatternComprehension.

Parameters:



15
16
17
18
19
20
21
22
23
24
# File 'lib/cyrel/expression/pattern_comprehension.rb', line 15

def initialize(pattern, projection_expression)
  unless pattern.is_a?(Cyrel::Pattern::Path) || pattern.is_a?(Cyrel::Pattern::Node) || pattern.is_a?(Cyrel::Pattern::Relationship)
    raise ArgumentError,
          "Pattern Comprehension pattern must be a Path, Node, or Relationship, got #{pattern.class}"
  end

  @pattern = pattern
  @projection_expression = Expression.coerce(projection_expression)
  # @where_condition = where_condition ? Expression.coerce(where_condition) : nil
end

Instance Attribute Details

#patternObject (readonly)

TODO: Add where_condition



9
10
11
# File 'lib/cyrel/expression/pattern_comprehension.rb', line 9

def pattern
  @pattern
end

#projection_expressionObject (readonly)

TODO: Add where_condition



9
10
11
# File 'lib/cyrel/expression/pattern_comprehension.rb', line 9

def projection_expression
  @projection_expression
end

Instance Method Details

#render(query) ⇒ String

Renders the pattern comprehension expression.

Parameters:

  • query (Cyrel::Query)

    The query object for rendering pattern and expression.

Returns:

  • (String)

    The Cypher string fragment.



29
30
31
32
33
34
35
# File 'lib/cyrel/expression/pattern_comprehension.rb', line 29

def render(query)
  pattern_str = @pattern.render(query)
  # where_str = @where_condition ? " WHERE #{@where_condition.render(query)}" : ""
  projection_str = @projection_expression.render(query)

  "[#{pattern_str} | #{projection_str}]" # Simplified: missing WHERE support
end