Class: Twb::Util::Graphnode

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#cypherCreateObject (readonly)

Returns the value of attribute cypherCreate.



47
48
49
# File 'lib/twb/util/graphnode.rb', line 47

def cypherCreate
  @cypherCreate
end

#cypherIDObject (readonly)

Returns the value of attribute cypherID.



47
48
49
# File 'lib/twb/util/graphnode.rb', line 47

def cypherID
  @cypherID
end

#idObject (readonly)

Returns the value of attribute id.



46
47
48
# File 'lib/twb/util/graphnode.rb', line 46

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'lib/twb/util/graphnode.rb', line 46

def name
  @name
end

#propertiesObject

attr_reader :cypherName, :cypherID, :cypherNodeID, :cypherType, :cypherCreate



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

def properties
  @properties
end

#typeObject (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_sObject



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

#dotLabelObject



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

Returns:

  • (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

#hashObject



86
87
88
# File 'lib/twb/util/graphnode.rb', line 86

def hash
  [@name, @id, @type, @properties].hash
end

#props_sObject



101
102
103
# File 'lib/twb/util/graphnode.rb', line 101

def props_s
  @properties.map{|k,v| "#{k}: #{v.inspect}"}.join(', ')
end

#to_sObject



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