Class: CircuitBreaker::Arc

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#sourceObject (readonly)

Returns the value of attribute source.



89
90
91
# File 'lib/circuit_breaker.rb', line 89

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



93
94
95
# File 'lib/circuit_breaker.rb', line 93

def target
  @target
end

#weightObject (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