Class: DepsGrapher::Node
- Inherits:
-
Object
- Object
- DepsGrapher::Node
- Defined in:
- lib/deps_grapher/node.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#deps_count ⇒ Object
Returns the value of attribute deps_count.
-
#id ⇒ Object
Returns the value of attribute id.
-
#location ⇒ Object
Returns the value of attribute location.
-
#parent ⇒ Object
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
- #increment_deps_count! ⇒ Object
-
#initialize(class_name, location) ⇒ Node
constructor
A new instance of Node.
- #label ⇒ Object
- #layer ⇒ Object
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_name ⇒ Object
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_count ⇒ Object
Returns the value of attribute deps_count.
34 35 36 |
# File 'lib/deps_grapher/node.rb', line 34 def deps_count @deps_count end |
#id ⇒ Object
Returns the value of attribute id.
34 35 36 |
# File 'lib/deps_grapher/node.rb', line 34 def id @id end |
#location ⇒ Object
Returns the value of attribute location.
34 35 36 |
# File 'lib/deps_grapher/node.rb', line 34 def location @location end |
#parent ⇒ Object
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 |
.all ⇒ Object
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 |
.guid ⇒ Object
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: ==
56 57 58 |
# File 'lib/deps_grapher/node.rb', line 56 def eql?(other) other.is_a?(self.class) && id == other.id end |
#hash ⇒ Object
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 |
#label ⇒ Object
44 45 46 |
# File 'lib/deps_grapher/node.rb', line 44 def label deps_count.positive? ? "#{class_name} (#{deps_count})" : class_name end |