Class: RSMP::Validator::Helpers::Startup::SignalGroupSequence
- Inherits:
-
Object
- Object
- RSMP::Validator::Helpers::Startup::SignalGroupSequence
- Defined in:
- lib/rsmp/validator/helpers/startup.rb
Overview
Tracks the startup signal group sequence for validation.
Instance Attribute Summary collapse
-
#latest ⇒ Object
readonly
Returns the value of attribute latest.
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
Instance Method Summary collapse
- #check(states) ⇒ Object
- #done? ⇒ Boolean
-
#initialize(sequence) ⇒ SignalGroupSequence
constructor
A new instance of SignalGroupSequence.
- #num_done ⇒ Object
- #num_started ⇒ Object
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
#latest ⇒ Object (readonly)
Returns the value of attribute latest.
10 11 12 |
# File 'lib/rsmp/validator/helpers/startup.rb', line 10 def latest @latest end |
#sequence ⇒ Object (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
28 29 30 |
# File 'lib/rsmp/validator/helpers/startup.rb', line 28 def done? num_done == @num_groups end |
#num_done ⇒ Object
24 25 26 |
# File 'lib/rsmp/validator/helpers/startup.rb', line 24 def num_done @pos.count { |pos| pos == @sequence.length - 1 } end |
#num_started ⇒ Object
20 21 22 |
# File 'lib/rsmp/validator/helpers/startup.rb', line 20 def num_started @pos.count { |v| !v.nil? } end |