Class: DepsGrapher::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/deps_grapher/node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, location) ⇒ Node

Returns a new instance of Node.



36
37
38
39
40
41
42
# File 'lib/deps_grapher/node.rb', line 36

def initialize(class_name, location)
  @id = "n#{self.class.guid}"
  @class_name = class_name
  @location = location
  @parent = nil
  @deps_count = 0
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



34
35
36
# File 'lib/deps_grapher/node.rb', line 34

def class_name
  @class_name
end

#deps_countObject

Returns the value of attribute deps_count.



34
35
36
# File 'lib/deps_grapher/node.rb', line 34

def deps_count
  @deps_count
end

#idObject

Returns the value of attribute id.



34
35
36
# File 'lib/deps_grapher/node.rb', line 34

def id
  @id
end

#locationObject

Returns the value of attribute location.



34
35
36
# File 'lib/deps_grapher/node.rb', line 34

def location
  @location
end

#parentObject

Returns the value of attribute parent.



34
35
36
# File 'lib/deps_grapher/node.rb', line 34

def parent
  @parent
end

Class Method Details

.add(class_name, location) ⇒ Object



15
16
17
18
19
# File 'lib/deps_grapher/node.rb', line 15

def add(class_name, location)
  return nil if class_name.nil? || location.nil?

  registry[class_name] ||= new class_name, location
end

.allObject



21
22
23
# File 'lib/deps_grapher/node.rb', line 21

def all
  registry.values
end

.fetch(class_name) ⇒ Object



11
12
13
# File 'lib/deps_grapher/node.rb', line 11

def fetch(class_name)
  registry[class_name]
end

.guidObject



6
7
8
9
# File 'lib/deps_grapher/node.rb', line 6

def guid
  @guid ||= 0
  @guid += 1
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


56
57
58
# File 'lib/deps_grapher/node.rb', line 56

def eql?(other)
  other.is_a?(self.class) && id == other.id
end

#hashObject



61
62
63
# File 'lib/deps_grapher/node.rb', line 61

def hash
  id.hash
end

#increment_deps_count!Object



52
53
54
# File 'lib/deps_grapher/node.rb', line 52

def increment_deps_count!
  @deps_count += 1
end

#labelObject



44
45
46
# File 'lib/deps_grapher/node.rb', line 44

def label
  deps_count.positive? ? "#{class_name} (#{deps_count})" : class_name
end

#layerObject



48
49
50
# File 'lib/deps_grapher/node.rb', line 48

def layer
  @layer ||= Layer.fetch(location).name
end