Class: DepsGrapher::Edge

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, from, to) ⇒ Edge

Returns a new instance of Edge.



43
44
45
46
47
# File 'lib/deps_grapher/edge.rb', line 43

def initialize(id, from, to)
  @id = id
  @from = from
  @to = to
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



41
42
43
# File 'lib/deps_grapher/edge.rb', line 41

def from
  @from
end

#idObject

Returns the value of attribute id.



41
42
43
# File 'lib/deps_grapher/edge.rb', line 41

def id
  @id
end

#toObject

Returns the value of attribute to.



41
42
43
# File 'lib/deps_grapher/edge.rb', line 41

def to
  @to
end

Class Method Details

.add(from, to) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/deps_grapher/edge.rb', line 11

def add(from, to)
  return nil if from.nil? || to.nil?

  id = generate_id from, to

  return nil if registry.key?(id) || from.id == to.id

  to.parent = from.id
  to.increment_deps_count!

  registry[id] = new id, from, to
end

.allObject



24
25
26
# File 'lib/deps_grapher/edge.rb', line 24

def all
  registry.values
end

.fetch(from, to) ⇒ Object



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

def fetch(from, to)
  id = generate_id from, to
  registry.fetch id
end

Instance Method Details

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

Returns:

  • (Boolean)


49
50
51
# File 'lib/deps_grapher/edge.rb', line 49

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

#hashObject



54
55
56
# File 'lib/deps_grapher/edge.rb', line 54

def hash
  id.hash
end