Class: RSMP::TLC::StartupSequence
- Inherits:
-
Object
- Object
- RSMP::TLC::StartupSequence
- Defined in:
- lib/rsmp/tlc/startup_sequence.rb
Overview
Manages startup sequence state machine for traffic controllers
Instance Attribute Summary collapse
-
#initiated_at ⇒ Object
readonly
Returns the value of attribute initiated_at.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #advance ⇒ Object
- #complete? ⇒ Boolean
- #current_state ⇒ Object
-
#initialize(sequence) ⇒ StartupSequence
constructor
A new instance of StartupSequence.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(sequence) ⇒ StartupSequence
7 8 9 10 11 12 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 7 def initialize(sequence) @sequence = sequence || [] @active = false @initiated_at = nil @position = nil end |
Instance Attribute Details
#initiated_at ⇒ Object (readonly)
Returns the value of attribute initiated_at.
5 6 7 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 5 def initiated_at @initiated_at end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
5 6 7 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 5 def position @position end |
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
5 6 7 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 5 def sequence @sequence end |
Instance Method Details
#active? ⇒ Boolean
26 27 28 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 26 def active? @active end |
#advance ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 45 def advance return unless @active if @initiated_at.nil? @initiated_at = Time.now.to_i + 1 @position = 0 else @position = Time.now.to_i - @initiated_at end stop if complete? end |
#complete? ⇒ Boolean
30 31 32 33 34 35 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 30 def complete? return false unless @active return false if @position.nil? @position >= @sequence.size end |
#current_state ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 37 def current_state return nil unless @active return nil if @position.nil? return nil if @position >= @sequence.size @sequence[@position] end |
#start ⇒ Object
14 15 16 17 18 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 14 def start @active = true @initiated_at = nil @position = nil end |
#stop ⇒ Object
20 21 22 23 24 |
# File 'lib/rsmp/tlc/startup_sequence.rb', line 20 def stop @active = false @initiated_at = nil @position = nil end |