Class: Redgraph::Node

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/redgraph/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#escape_value, #properties_to_string

Constructor Details

#initialize(label: nil, properties: nil, id: nil, labels: nil) ⇒ Node

Returns a new instance of Node.

Raises:



9
10
11
12
13
14
# File 'lib/redgraph/node.rb', line 9

def initialize(label: nil, properties: nil, id: nil, labels: nil)
  @id = id
  raise(Error, "You can either define a single label or a label array") if label && labels
  @labels = labels || (label ? [label] : [])
  @properties = (properties || {}).with_indifferent_access
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/redgraph/node.rb', line 7

def id
  @id
end

#labelsObject

Returns the value of attribute labels.



7
8
9
# File 'lib/redgraph/node.rb', line 7

def labels
  @labels
end

#propertiesObject

Returns the value of attribute properties.



7
8
9
# File 'lib/redgraph/node.rb', line 7

def properties
  @properties
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/redgraph/node.rb', line 24

def ==(other)
  super || other.instance_of?(self.class) && !id.nil? && other.id == id
end

#labelObject



16
17
18
# File 'lib/redgraph/node.rb', line 16

def label
  labels.first
end

#persisted?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/redgraph/node.rb', line 20

def persisted?
  id.present?
end

#to_query_string(item_alias: 'node') ⇒ Object



28
29
30
31
# File 'lib/redgraph/node.rb', line 28

def to_query_string(item_alias: 'node')
  _label = labels.map {|l| ":`#{l}`"}.join
  "(#{item_alias}#{_label} #{properties_to_string(properties)})"
end