Class: Twb::Util::Graphnode
- Inherits:
-
Object
- Object
- Twb::Util::Graphnode
- Defined in:
- lib/twb/util/graphnode.rb
Constant Summary collapse
- @@stripChars =
/[.: %-\-\(\)=]/
- @@replChar =
'_'
- @@typeShapes =
{ :CalculatedField => 'shape=note', :DBTable => 'shape=ellipse', :TwbDataConnection => '', :DatabaseField => '' }
- @@typeColors =
{ :CalculatedField => 'fillcolor=lightskyblue3', :DBTable => 'fillcolor=steelblue', :TwbDataConnection => 'fillcolor=cornflowerblue', :DatabaseField => 'fillcolor=grey', }
- @@typeStyles =
not currently used
{ :CalculatedField => 'style=filled', :DBTable => 'style=filled', :TwbDataConnection => 'style=filled', :DatabaseField => 'style=filled' }
Instance Attribute Summary collapse
-
#cypherCreate ⇒ Object
readonly
Returns the value of attribute cypherCreate.
-
#cypherID ⇒ Object
readonly
Returns the value of attribute cypherID.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
attr_reader :cypherName, :cypherID, :cypherNodeID, :cypherType, :cypherCreate.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #cypher_s ⇒ Object
- #cypherize(str) ⇒ Object
- #dotLabel ⇒ Object
- #enquote(str) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, id:, type:, properties: {}) ⇒ Graphnode
constructor
Neo4J cypher variable quote character: ‘.
- #props_s ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name:, id:, type:, properties: {}) ⇒ Graphnode
Neo4J cypher variable quote character: ‘
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/twb/util/graphnode.rb', line 53 def initialize (name:, id:, type:, properties: {}) @id = id @type = type @name = name @properties = properties # -- @cypherID = '`' + id + '`' # @cypherType = type # @cypherName = name @properties['name'] = name unless @properties.key? 'name' @cypherCreate = "CREATE (%s:`%s` {%s})" % [@cypherID,type,props_s] end |
Instance Attribute Details
#cypherCreate ⇒ Object (readonly)
Returns the value of attribute cypherCreate.
47 48 49 |
# File 'lib/twb/util/graphnode.rb', line 47 def cypherCreate @cypherCreate end |
#cypherID ⇒ Object (readonly)
Returns the value of attribute cypherID.
47 48 49 |
# File 'lib/twb/util/graphnode.rb', line 47 def cypherID @cypherID end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
46 47 48 |
# File 'lib/twb/util/graphnode.rb', line 46 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/twb/util/graphnode.rb', line 46 def name @name end |
#properties ⇒ Object
attr_reader :cypherName, :cypherID, :cypherNodeID, :cypherType, :cypherCreate
49 50 51 |
# File 'lib/twb/util/graphnode.rb', line 49 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
46 47 48 |
# File 'lib/twb/util/graphnode.rb', line 46 def type @type end |
Instance Method Details
#cypher_s ⇒ Object
96 97 98 |
# File 'lib/twb/util/graphnode.rb', line 96 def cypher_s "name:%s id:%s t:%s p:{%s}" % [name, @cypherID, @type, props_s] end |
#cypherize(str) ⇒ Object
67 68 69 |
# File 'lib/twb/util/graphnode.rb', line 67 def cypherize str enquote str.gsub(@@stripChars,@@replChar) end |
#dotLabel ⇒ Object
76 77 78 |
# File 'lib/twb/util/graphnode.rb', line 76 def dotLabel "\"%s\" [label=\"%s\" %s %s ]" % [id, name.gsub('"','\"'), @@typeShapes[@type], @@typeColors[@type]] end |
#enquote(str) ⇒ Object
71 72 73 |
# File 'lib/twb/util/graphnode.rb', line 71 def enquote str str.gsub("'","\\\\'") end |
#eql?(other) ⇒ Boolean
81 82 83 |
# File 'lib/twb/util/graphnode.rb', line 81 def eql? other @name == other.name && @id == other.id && @type == other.type && @properties == other.properties end |
#hash ⇒ Object
86 87 88 |
# File 'lib/twb/util/graphnode.rb', line 86 def hash [@name, @id, @type, @properties].hash end |
#props_s ⇒ Object
101 102 103 |
# File 'lib/twb/util/graphnode.rb', line 101 def props_s @properties.map{|k,v| "#{k}: #{v.inspect}"}.join(', ') end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/twb/util/graphnode.rb', line 91 def to_s "name:'%s' id:'%s' t:'%s' p:%s" % [@name, @id, @type, @properties.to_s] end |