Class: CypherBuilder::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/cypher_builder/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix = nil, name) ⇒ Field

Returns a new instance of Field.



9
10
11
# File 'lib/cypher_builder/field.rb', line 9

def initialize(prefix = nil, name)
  @prefix, @name = prefix, name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cypher_builder/field.rb', line 7

def name
  @name
end

Instance Method Details

#aliasedObject



25
26
27
# File 'lib/cypher_builder/field.rb', line 25

def aliased
  sprintf('%s AS %s', prefixed_name, name)
end

#as_cypher(payload:, context:) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/cypher_builder/field.rb', line 13

def as_cypher(payload:, context:)
  if context.ancestor?(Return) && !context.ancestor?(Alias)
    aliased
  else
    prefixed_name
  end
end

#prefixed_nameObject



21
22
23
# File 'lib/cypher_builder/field.rb', line 21

def prefixed_name
  [@prefix, @name].compact.join('.')
end