Class: RSMP::Validator::Helpers::Startup::SignalGroupSequence

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/validator/helpers/startup.rb

Overview

Tracks the startup signal group sequence for validation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequence) ⇒ SignalGroupSequence

Returns a new instance of SignalGroupSequence.



12
13
14
15
16
17
18
# File 'lib/rsmp/validator/helpers/startup.rb', line 12

def initialize(sequence)
  @pos = []
  @prev = []
  @sequence = sequence
  @num_groups = 0
  @latest = nil
end

Instance Attribute Details

#latestObject (readonly)

Returns the value of attribute latest.



10
11
12
# File 'lib/rsmp/validator/helpers/startup.rb', line 10

def latest
  @latest
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



10
11
12
# File 'lib/rsmp/validator/helpers/startup.rb', line 10

def sequence
  @sequence
end

Instance Method Details

#check(states) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rsmp/validator/helpers/startup.rb', line 32

def check(states)
  initialize_check(states)

  states.each_char.with_index do |state, group_index|
    position = @pos[group_index]
    error = if position
              check_started_group(group_index, state, position)
            else
              check_not_started_group(group_index, state)
            end
    return error if error
  end

  :ok
end

#done?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rsmp/validator/helpers/startup.rb', line 28

def done?
  num_done == @num_groups
end

#num_doneObject



24
25
26
# File 'lib/rsmp/validator/helpers/startup.rb', line 24

def num_done
  @pos.count { |pos| pos == @sequence.length - 1 }
end

#num_startedObject



20
21
22
# File 'lib/rsmp/validator/helpers/startup.rb', line 20

def num_started
  @pos.count { |v| !v.nil? }
end