Class: Link
- Inherits:
-
Object
- Object
- Link
- Defined in:
- lib/cpp_dependency_graph/link.rb
Overview
Represents a link between two entities, a source and a target
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cyclic? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(source, target, cyclic = false) ⇒ Link
constructor
A new instance of Link.
- #to_json(*options) ⇒ Object
- #to_s ⇒ Object
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
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/cpp_dependency_graph/link.rb', line 8 def source @source end |
#target ⇒ Object (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
17 18 19 |
# File 'lib/cpp_dependency_graph/link.rb', line 17 def cyclic? @cyclic end |
#hash ⇒ Object
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(*) { json_class: self.class.name, source: source, target: target, cyclic: cyclic? }.to_json(*) end |
#to_s ⇒ Object
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 |