Class: Validator::StatusHelpers::SignalGroupSequenceHelper

Inherits:
Object
  • Object
show all
Defined in:
spec/support/signal_group_sequence_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequence) ⇒ SignalGroupSequenceHelper

Returns a new instance of SignalGroupSequenceHelper.



5
6
7
8
9
10
# File 'spec/support/signal_group_sequence_helper.rb', line 5

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

Instance Attribute Details

#latestObject (readonly)

Returns the value of attribute latest.



3
4
5
# File 'spec/support/signal_group_sequence_helper.rb', line 3

def latest
  @latest
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



3
4
5
# File 'spec/support/signal_group_sequence_helper.rb', line 3

def sequence
  @sequence
end

Instance Method Details

#check(states) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'spec/support/signal_group_sequence_helper.rb', line 24

def check states
  @latest = states
  @num_groups = states.size
  states.each_char.with_index do |state,i|
    pos = @pos[i]                 # current pos
    if pos                        # if the group has already started:
      current = @sequence[ pos ]  # get current state
      if state != current         # did the state change?
        if pos == @sequence.length-1        # at end?
          expected  = @sequence[-1]         # if at end, expected to stay there
        else
          next_pos = pos + 1
          expected = @sequence[ next_pos ] # if not at end expected to move to the next state in sequence
        end
        if state != expected      # did it go to, or stay in, the expected state?
          return "Group #{i} changed from #{current} to #{state}, must go to #{expected}"
        end
        @pos[i] = next_pos        # move position
      end
    else                          # if the group didn't start yet:
      if state == @sequence[0]    # look for start of sequence
        @pos[i] = 0               # start at pos 0
      end
    end
  end
  return :ok
end

#done?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'spec/support/signal_group_sequence_helper.rb', line 20

def done?
  num_done == @num_groups
end

#num_doneObject



16
17
18
# File 'spec/support/signal_group_sequence_helper.rb', line 16

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

#num_startedObject



12
13
14
# File 'spec/support/signal_group_sequence_helper.rb', line 12

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