Class: Twb::Util::GMLedge

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/util/gmledge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from:, to:, relationship:, properties: {}) ⇒ GMLedge

Neo4J cypher variable quote character: `

Raises:

  • (ArgumentError)

31
32
33
34
35
36
37
38
39
# File 'lib/twb/util/gmledge.rb', line 31

def initialize (from:, to:, relationship:, properties: {})
  raise ArgumentError.new("from: parameter must be a Graphnode, is a '#{from.class}'") unless from.is_a? Twb::Util::Graphnode
  raise ArgumentError.new(  "to: parameter must be a Graphnode, is a '#{to.class}'"  ) unless   to.is_a? Twb::Util::Graphnode
  @from         = from
  @to           = to
  @relationship = relationship
  @properties   = properties
  @cypherCreate = "CREATE  #{cypher_s}"
end

Instance Attribute Details

#cypherCreateObject (readonly)

Returns the value of attribute cypherCreate


27
28
29
# File 'lib/twb/util/gmledge.rb', line 27

def cypherCreate
  @cypherCreate
end

#fromObject (readonly)

Returns the value of attribute from


25
26
27
# File 'lib/twb/util/gmledge.rb', line 25

def from
  @from
end

#propertiesObject

Returns the value of attribute properties


26
27
28
# File 'lib/twb/util/gmledge.rb', line 26

def properties
  @properties
end

#relationshipObject (readonly)

Returns the value of attribute relationship


25
26
27
# File 'lib/twb/util/gmledge.rb', line 25

def relationship
  @relationship
end

#toObject (readonly)

Returns the value of attribute to


25
26
27
# File 'lib/twb/util/gmledge.rb', line 25

def to
  @to
end

Instance Method Details

#cypher_sObject


62
63
64
# File 'lib/twb/util/gmledge.rb', line 62

def cypher_s
  "(%s)-[:`%s`]->(%s)" % [@from.cypherID,@relationship,@to.cypherID]
end

#dotObject


53
54
55
# File 'lib/twb/util/gmledge.rb', line 53

def dot
  "%s  ->  %s" % [dotquote(from.id), dotquote(to.id)]
end

#dotquote(str) ⇒ Object


57
58
59
60
# File 'lib/twb/util/gmledge.rb', line 57

def dotquote str
  ns = str.gsub(/(["])/,'\\"')
  return "\"#{ns}\""
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/twb/util/gmledge.rb', line 41

def eql? other
  @from == other.from && @to == other.to && @relationship == other.relationship && @properties == other.properties
end

#gmlObject


66
67
68
# File 'lib/twb/util/gmledge.rb', line 66

def gml
  "%s  ->  %s" % [dotquote(from.id), dotquote(to.id)]
end

#hashObject


45
46
47
# File 'lib/twb/util/gmledge.rb', line 45

def hash
  [@from.hash, @to.hash, @relationship, @properties].hash
end

#to_sObject


49
50
51
# File 'lib/twb/util/gmledge.rb', line 49

def to_s
  "'#{@from.name}//{@from.id}' --#{@relationship}--> '#{@to.name}//#{@to.id}'"
end