Class: Twb::Util::Graphnode
- Inherits:
-
Object
- Object
- Twb::Util::Graphnode
- Includes:
- Comparable
- Defined in:
- lib/twb/util/graphnode.rb
Overview
< TabClass
Constant Summary collapse
- @@hasher =
Digest::SHA256.new
- @@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 =
{ :CalculatedField => 'style=filled', :DBTable => 'style=filled', :TwbDataConnection => 'style=filled', :DatabaseField => 'style=filled' }
Instance Attribute Summary collapse
-
#colour ⇒ Object
Returns the value of attribute colour.
-
#dotid ⇒ Object
readonly
Returns the value of attribute dotid.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #deModule(fqClass) ⇒ Object
- #dotLabel ⇒ Object
- #dotquote(str) ⇒ Object
- #enquote(str) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, id:, type:, properties: {}) ⇒ Graphnode
constructor
A new instance of Graphnode.
- #props_s ⇒ Object
- #resolveType(type) ⇒ Object
-
#to_s ⇒ Object
def uuid @uuid ||= @uuid = SecureRandom.uuid # @uuid ||= Digest::MD5.hexdigest(id) end.
Constructor Details
#initialize(name:, id:, type:, properties: {}) ⇒ Graphnode
Returns a new instance of Graphnode.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/twb/util/graphnode.rb', line 51 def initialize (name:, id:, type:, properties: {}) # puts "graphNode : t: %-20s tc: %s " % [type, type.class] @id = id @uuid = SecureRandom.uuid # @type = type.instance_of?(Class) ? type : type.class @type = resolveType type # puts " : t: %-20s tc: %s \n " % [@type, @type.class] @name = name @colour = nil @properties = properties @properties['name'] = name unless @properties.key? 'name' if @name.nil? raise ArgumentError, "Graphnode Initialize Error - name:'#{@name}' id:'#{@id}' type:'#{type}' properties:'@properties.inspect'" end end |
Instance Attribute Details
#colour ⇒ Object
Returns the value of attribute colour.
49 50 51 |
# File 'lib/twb/util/graphnode.rb', line 49 def colour @colour end |
#dotid ⇒ Object (readonly)
Returns the value of attribute dotid.
48 49 50 |
# File 'lib/twb/util/graphnode.rb', line 48 def dotid @dotid end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
48 49 50 |
# File 'lib/twb/util/graphnode.rb', line 48 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
48 49 50 |
# File 'lib/twb/util/graphnode.rb', line 48 def name @name end |
#properties ⇒ Object
Returns the value of attribute properties.
49 50 51 |
# File 'lib/twb/util/graphnode.rb', line 49 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
48 49 50 |
# File 'lib/twb/util/graphnode.rb', line 48 def type @type end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
48 49 50 |
# File 'lib/twb/util/graphnode.rb', line 48 def uuid @uuid end |
Instance Method Details
#<=>(other) ⇒ Object
120 121 122 |
# File 'lib/twb/util/graphnode.rb', line 120 def <=>(other) hash <=> other.hash end |
#deModule(fqClass) ⇒ Object
78 79 80 |
# File 'lib/twb/util/graphnode.rb', line 78 def deModule fqClass fqClass.class.name.split('::').last end |
#dotLabel ⇒ Object
86 87 88 |
# File 'lib/twb/util/graphnode.rb', line 86 def dotLabel "%s [label=\"%s\" %s %s ]" % [dotid, name.gsub('"','\"'), @@typeShapes[@type], @@typeColors[@type]] end |
#dotquote(str) ⇒ Object
94 95 96 97 |
# File 'lib/twb/util/graphnode.rb', line 94 def dotquote str ns = str.instance_of?(String) ? str.gsub(/(["])/,'\\"') : str.to_s return "\"#{ns}\"" end |
#enquote(str) ⇒ Object
82 83 84 |
# File 'lib/twb/util/graphnode.rb', line 82 def enquote str str.gsub("'","\\\\'") end |
#eql?(other) ⇒ Boolean
99 100 101 |
# File 'lib/twb/util/graphnode.rb', line 99 def eql? other @name == other.name && @id == other.id && @type == other.type && @properties == other.properties end |
#hash ⇒ Object
103 104 105 |
# File 'lib/twb/util/graphnode.rb', line 103 def hash [@name, @id, @type, @properties].hash end |
#props_s ⇒ Object
116 117 118 |
# File 'lib/twb/util/graphnode.rb', line 116 def props_s @props_s ||= @properties.map{|k,v| "#{k}: #{v.inspect}"}.join(', ') end |
#resolveType(type) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/twb/util/graphnode.rb', line 67 def resolveType type if type.instance_of?(Class) deModule(type) elsif type.instance_of?(Symbol) type.to_s elsif type.instance_of?(String) type else deModule(type) end end |
#to_s ⇒ Object
def uuid
@uuid ||= @uuid = SecureRandom.uuid
# @uuid ||= Digest::MD5.hexdigest(id)
end
112 113 114 |
# File 'lib/twb/util/graphnode.rb', line 112 def to_s "name:'%s' id:'%s' t:'%s' p:%s" % [@name, @id, @type, @properties.to_s] end |