Class: Link

Inherits:
Object
  • Object
show all
Defined in:
lib/cpp_dependency_graph/link.rb

Overview

Represents a link between two entities, a source and a target

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, cyclic = false) ⇒ Link

Returns a new instance of Link.



11
12
13
14
15
# File 'lib/cpp_dependency_graph/link.rb', line 11

def initialize(source, target, cyclic = false)
  @source = source
  @target = target
  @cyclic = cyclic
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/cpp_dependency_graph/link.rb', line 8

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/cpp_dependency_graph/link.rb', line 9

def target
  @target
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
# File 'lib/cpp_dependency_graph/link.rb', line 21

def ==(other)
  (source == other.source && target == other.target && cyclic? == other.cyclic?) ||
    (source == other.target && target == other.source && cyclic? == other.cyclic?)
end

#cyclic?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cpp_dependency_graph/link.rb', line 17

def cyclic?
  @cyclic
end

#hashObject



26
27
28
# File 'lib/cpp_dependency_graph/link.rb', line 26

def hash
  [source, target, cyclic?].to_set.hash
end

#to_json(*options) ⇒ Object



38
39
40
41
# File 'lib/cpp_dependency_graph/link.rb', line 38

def to_json(*options)
  { json_class: self.class.name,
    source: source, target: target, cyclic: cyclic? }.to_json(*options)
end

#to_sObject



30
31
32
33
34
35
36
# File 'lib/cpp_dependency_graph/link.rb', line 30

def to_s
  if cyclic?
    "#{source} <-> #{target}"
  else
    "#{source} -> #{target}"
  end
end