class Neo4j::Cypher::Operator

Attributes

eval_context[R]
left_operand[R]
neg[R]
op[R]
right_operand[R]

Public Class Methods

new(clause_list, left_operand, right_operand, op, clause_type = :where, post_fix = nil, &dsl) click to toggle source
Calls superclass method Neo4j::Cypher::Clause::new
   # File lib/neo4j-cypher/operator.rb
38 def initialize(clause_list, left_operand, right_operand, op, clause_type = :where, post_fix = nil, &dsl)
39   super(clause_list, clause_type, EvalContext)
40   if op == '='
41     right_operand = right_operand.nil? ? :NULL : right_operand
42   end
43   right_operand = Regexp.new(right_operand) if op == '=~' && right_operand.is_a?(String)
44   @left_operand = Operand.new(left_operand)
45   raise "No Leftoperatnd #{left_operand.class}" unless @left_operand.obj
46   @right_operand = Operand.new(right_operand) unless right_operand.nil?
47   @op = (@right_operand && @right_operand.regexp?) ? '=~' : op
48   @post_fix = post_fix
49   @valid = true
50 
51   # since we handle it ourself in to_cypher method unless it needs to be declared (as a cypher start node/relationship)
52   clause_list.delete(left_operand) if remove_operand?(left_operand)
53   clause_list.delete(right_operand) if remove_operand?(right_operand)
54   @neg = nil
55 end

Public Instance Methods

match_value() click to toggle source
   # File lib/neo4j-cypher/operator.rb
62 def match_value
63   @left_operand.obj.match_value || expr
64 end
not() click to toggle source
   # File lib/neo4j-cypher/operator.rb
75 def not
76   @neg = "not"
77 end
remove_operand?(operand) click to toggle source
   # File lib/neo4j-cypher/operator.rb
57 def remove_operand?(operand)
58   clause = operand.respond_to?(:clause) ? operand.clause : operand
59   clause.kind_of?(Clause) && clause.clause_type == :where
60 end
return_value() click to toggle source
   # File lib/neo4j-cypher/operator.rb
71 def return_value
72   (@right_operand || @unary) ? @left_operand.obj.var_name : to_cypher
73 end
to_cypher() click to toggle source
   # File lib/neo4j-cypher/operator.rb
88 def to_cypher
89   if @right_operand
90     neg ? "#{neg}(#{@left_operand.to_s} #{op} #{@right_operand.to_s})" : "#{@left_operand.to_s} #{op} #{@right_operand.to_s}"
91   else
92     left_p, right_p = @left_operand.to_s[0..0] == '(' ? ['', ''] : ['(', ')']
93     # binary operator
94     neg ? "#{neg}#{op}(#{@left_operand.to_s}#{@post_fix})" : "#{op}#{left_p}#{@left_operand.to_s}#{@post_fix}#{right_p}"
95   end
96 end
to_s() click to toggle source
   # File lib/neo4j-cypher/operator.rb
84 def to_s
85   to_cypher
86 end
unary!() click to toggle source
   # File lib/neo4j-cypher/operator.rb
79 def unary!
80   @unary = true # TODO needed ?
81   eval_context
82 end
var_name() click to toggle source
   # File lib/neo4j-cypher/operator.rb
67 def var_name
68   @left_operand.obj.var_name
69 end