Class: CircuitBreaker::Arc
- Inherits:
-
Object
- Object
- CircuitBreaker::Arc
- Defined in:
- lib/circuit_breaker.rb
Overview
Represents an arc connecting places and transitions in the Petri net Arcs can have weights to specify how many tokens are required/produced
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Check if this arc is enabled (can fire).
-
#initialize(source, target, weight = 1) ⇒ Arc
constructor
Initialize a new arc.
Constructor Details
#initialize(source, target, weight = 1) ⇒ Arc
Initialize a new arc
99 100 101 102 103 |
# File 'lib/circuit_breaker.rb', line 99 def initialize(source, target, weight = 1) @source = source @target = target @weight = weight end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
89 90 91 |
# File 'lib/circuit_breaker.rb', line 89 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
93 94 95 |
# File 'lib/circuit_breaker.rb', line 93 def target @target end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
85 86 87 |
# File 'lib/circuit_breaker.rb', line 85 def weight @weight end |
Instance Method Details
#enabled? ⇒ Boolean
Check if this arc is enabled (can fire)
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/circuit_breaker.rb', line 107 def enabled? case source when Place source.token_count >= weight when Transition true # Transitions can always produce tokens else false end end |