Class: Neo4j::Cypher::Operator

Inherits:
Object
  • Object
show all
Includes:
Clause
Defined in:
lib/neo4j-cypher/operator.rb

Defined Under Namespace

Classes: EvalContext

Constant Summary

Constants included from Clause

Clause::NAME, Clause::ORDER

Instance Attribute Summary collapse

Attributes included from Clause

#clause_list, #clause_type, #expr, #insert_order

Instance Method Summary collapse

Methods included from Clause

#<=>, #alias_name, #as_alias, #as_alias?, #clause_position, #create_clause_args_for, #match_value=, #prefix, #referenced!, #referenced?, #separator, #to_prop_string, #valid_clause?, #var_name=

Constructor Details

#initialize(clause_list, left_operand, right_operand, op, clause_type = :where, post_fix = nil, &dsl) ⇒ Operator

Returns a new instance of Operator.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/neo4j-cypher/operator.rb', line 38

def initialize(clause_list, left_operand, right_operand, op, clause_type = :where, post_fix = nil, &dsl)
  super(clause_list, clause_type, EvalContext)
  right_operand ||= :NULL if op == '='
  right_operand = Regexp.new(right_operand) if op == '=~' && right_operand.is_a?(String)
  @left_operand = Operand.new(left_operand)
  raise "No Leftoperatnd #{left_operand.class}" unless @left_operand.obj
  @right_operand = Operand.new(right_operand) unless right_operand.nil?
  @op = (@right_operand && @right_operand.regexp?) ? '=~' : op
  @post_fix = post_fix
  @valid = true

  # since we handle it ourself in to_cypher method unless it needs to be declared (as a cypher start node/relationship)
  clause_list.delete(left_operand) if remove_operand?(left_operand)
  clause_list.delete(right_operand) if remove_operand?(right_operand)
  @neg = nil
end

Instance Attribute Details

#eval_contextObject (readonly)

Returns the value of attribute eval_context.



35
36
37
# File 'lib/neo4j-cypher/operator.rb', line 35

def eval_context
  @eval_context
end

#left_operandObject (readonly)

Returns the value of attribute left_operand.



35
36
37
# File 'lib/neo4j-cypher/operator.rb', line 35

def left_operand
  @left_operand
end

#negObject (readonly)

Returns the value of attribute neg.



35
36
37
# File 'lib/neo4j-cypher/operator.rb', line 35

def neg
  @neg
end

#opObject (readonly)

Returns the value of attribute op.



35
36
37
# File 'lib/neo4j-cypher/operator.rb', line 35

def op
  @op
end

#right_operandObject (readonly)

Returns the value of attribute right_operand.



35
36
37
# File 'lib/neo4j-cypher/operator.rb', line 35

def right_operand
  @right_operand
end

Instance Method Details

#match_valueObject



60
61
62
# File 'lib/neo4j-cypher/operator.rb', line 60

def match_value
  @left_operand.obj.match_value || expr
end

#notObject



73
74
75
# File 'lib/neo4j-cypher/operator.rb', line 73

def not
  @neg = "not"
end

#remove_operand?(operand) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/neo4j-cypher/operator.rb', line 55

def remove_operand?(operand)
  clause = operand.respond_to?(:clause) ? operand.clause : operand
  clause.kind_of?(Clause) && clause.clause_type == :where
end

#return_valueObject



69
70
71
# File 'lib/neo4j-cypher/operator.rb', line 69

def return_value
  (@right_operand || @unary) ? @left_operand.obj.var_name : to_cypher
end

#to_cypherObject



86
87
88
89
90
91
92
93
94
# File 'lib/neo4j-cypher/operator.rb', line 86

def to_cypher
  if @right_operand
    neg ? "#{neg}(#{@left_operand.to_s} #{op} #{@right_operand.to_s})" : "#{@left_operand.to_s} #{op} #{@right_operand.to_s}"
  else
    left_p, right_p = @left_operand.to_s[0..0] == '(' ? ['', ''] : ['(', ')']
    # binary operator
    neg ? "#{neg}#{op}(#{@left_operand.to_s}#{@post_fix})" : "#{op}#{left_p}#{@left_operand.to_s}#{@post_fix}#{right_p}"
  end
end

#to_sObject



82
83
84
# File 'lib/neo4j-cypher/operator.rb', line 82

def to_s
  to_cypher
end

#unary!Object



77
78
79
80
# File 'lib/neo4j-cypher/operator.rb', line 77

def unary!
  @unary = true # TODO needed ?
  eval_context
end

#var_nameObject



65
66
67
# File 'lib/neo4j-cypher/operator.rb', line 65

def var_name
  @left_operand.obj.var_name
end