class Twb::Util::Graphnode

Attributes

colour[RW]
dotid[R]
id[R]
name[R]
properties[RW]
type[R]
uuid[R]

Public Class Methods

new(name:, id:, type:, properties: {}) click to toggle source
# 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

Public Instance Methods

<=>(other) click to toggle source
# File lib/twb/util/graphnode.rb, line 120
def <=>(other)
  hash <=> other.hash
end
deModule(fqClass) click to toggle source
# File lib/twb/util/graphnode.rb, line 78
def deModule fqClass
  fqClass.class.name.split('::').last
end
dotLabel() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/twb/util/graphnode.rb, line 82
def enquote str
  str.gsub("'","\\\\'")
end
eql?(other) click to toggle source
# 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() click to toggle source
# File lib/twb/util/graphnode.rb, line 103
def hash
  [@name, @id, @type, @properties].hash
end
props_s() click to toggle source
# File lib/twb/util/graphnode.rb, line 116
def props_s
  @props_s ||= @properties.map{|k,v| "#{k}: #{v.inspect}"}.join(', ')
end
resolveType(type) click to toggle source
# 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() click to toggle source

def uuid

@uuid ||= @uuid = SecureRandom.uuid
# @uuid ||= Digest::MD5.hexdigest(id)

end

# 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