Class: RSMP::TLC::StartupSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/tlc/startup_sequence.rb

Overview

Manages startup sequence state machine for traffic controllers

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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

#positionObject (readonly)

Returns the value of attribute position.



5
6
7
# File 'lib/rsmp/tlc/startup_sequence.rb', line 5

def position
  @position
end

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

#advanceObject



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_stateObject



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

#startObject



14
15
16
17
18
# File 'lib/rsmp/tlc/startup_sequence.rb', line 14

def start
  @active = true
  @initiated_at = nil
  @position = nil
end

#stopObject



20
21
22
23
24
# File 'lib/rsmp/tlc/startup_sequence.rb', line 20

def stop
  @active = false
  @initiated_at = nil
  @position = nil
end