Class: ChaosDetector::GraphTheory::Edge
- Inherits:
-
Object
- Object
- ChaosDetector::GraphTheory::Edge
- Defined in:
- lib/chaos_detector/graph_theory/edge.rb
Direct Known Subclasses
Constant Summary collapse
- EDGE_TYPES =
{ default: 0, superclass: 1, association: 2, class_association: 3 }.freeze
Instance Attribute Summary collapse
-
#dep_node ⇒ Object
Returns the value of attribute dep_node.
-
#edge_type ⇒ Object
Returns the value of attribute edge_type.
-
#graph_props ⇒ Object
Default behavior is accessor for @graph_props.
-
#reduction ⇒ Object
Returns the value of attribute reduction.
-
#src_node ⇒ Object
Returns the value of attribute src_node.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #edge_rank ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(src_node, dep_node, edge_type: :default, reduction: nil) ⇒ Edge
constructor
A new instance of Edge.
-
#merge!(other) ⇒ Object
Mutate this Edge; combining attributes from other:.
- #to_s ⇒ Object
- #weight ⇒ Object
Constructor Details
#initialize(src_node, dep_node, edge_type: :default, reduction: nil) ⇒ Edge
Returns a new instance of Edge.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 17 def initialize(src_node, dep_node, edge_type: :default, reduction: nil) raise ArgumentError, 'src_node is required ' unless src_node raise ArgumentError, 'dep_node is required ' unless dep_node @src_node = src_node @dep_node = dep_node @reduction = reduction @edge_type = edge_type @graph_props = {} end |
Instance Attribute Details
#dep_node ⇒ Object
Returns the value of attribute dep_node.
7 8 9 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 7 def dep_node @dep_node end |
#edge_type ⇒ Object
Returns the value of attribute edge_type.
4 5 6 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 4 def edge_type @edge_type end |
#graph_props ⇒ Object
Default behavior is accessor for @graph_props
45 46 47 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 45 def graph_props @graph_props end |
#reduction ⇒ Object
Returns the value of attribute reduction.
8 9 10 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 8 def reduction @reduction end |
#src_node ⇒ Object
Returns the value of attribute src_node.
6 7 8 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 6 def src_node @src_node end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 54 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 51 def ==(other) # puts "Checking src and dep" src_node == other.src_node && dep_node == other.dep_node end |
#edge_rank ⇒ Object
28 29 30 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 28 def edge_rank EDGE_TYPES.fetch(@edge_type, 0) end |
#eql?(other) ⇒ Boolean
40 41 42 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 40 def eql?(other) self == other end |
#hash ⇒ Object
36 37 38 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 36 def hash [@src_node, @dep_node].hash end |
#merge!(other) ⇒ Object
Mutate this Edge; combining attributes from other:
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 63 def merge!(other) raise ArgumentError, ('Argument other should be Edge object (was %s)' % other.class) unless other.is_a?(Edge) if EDGE_TYPES.dig(other.edge_type) > EDGE_TYPES.dig(edge_type) @edge_type = other.edge_type end # puts("EDGE REDUCTION: #{@reduction.class} -- #{other.class} // #{other.reduction.class}") @reduction = ChaosDetector::GraphTheory::Reduction.combine(@reduction, other.reduction) self end |
#to_s ⇒ Object
56 57 58 59 60 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 56 def to_s s = format('[%s] -> [%s]', src_node.title, dep_node.title) s << "(#{reduction.reduction_sum})" if reduction&.reduction_sum.to_i > 1 s end |
#weight ⇒ Object
32 33 34 |
# File 'lib/chaos_detector/graph_theory/edge.rb', line 32 def weight @reduction&.reduction_sum || 1 end |