Module: Trailblazer::Activity::DSL::Linear::Sequence::Search

Defined in:
lib/trailblazer/activity/dsl/linear/sequence/search.rb

Class Method Summary collapse

Class Method Details

.ById(output, id) ⇒ Object

Find the seq_row with id and connect the current node to it.



35
36
37
38
39
40
41
42
# File 'lib/trailblazer/activity/dsl/linear/sequence/search.rb', line 35

def ById(output, id)
  ->(sequence, me) do
    index          = Adds::Insert.find_index(sequence, id) or return output, sequence[0] # FIXME # or raise "Couldn't find {#{id}}"
    target_seq_row = sequence[index]

    return output, target_seq_row
  end
end

.find_in_range(range, target_color) ⇒ Object



45
46
47
# File 'lib/trailblazer/activity/dsl/linear/sequence/search.rb', line 45

def find_in_range(range, target_color)
  _target_seq_row = range.find { |seq_row| seq_row[0] == target_color }
end

.Forward(output, target_color) ⇒ Object

From this task onwards, find the next task that’s “magnetic to” target_color. Note that we only go forward, no back-references are done here.



12
13
14
15
16
17
18
# File 'lib/trailblazer/activity/dsl/linear/sequence/search.rb', line 12

def Forward(output, target_color)
  ->(sequence, me) do
    target_seq_row = find_in_range(sequence[sequence.index(me) + 1..-1], target_color)

    return output, target_seq_row
  end
end

.WrapAround(output, target_color) ⇒ Object

Tries to find a track colored step by doing a Forward-search, first, then wraps around going through all steps from sequence start to self.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/trailblazer/activity/dsl/linear/sequence/search.rb', line 22

def WrapAround(output, target_color)
  ->(sequence, me) do
    my_index      = sequence.index(me)
    # First, try all elements after me, then go through the elements preceding myself.
    wrapped_range = sequence[my_index + 1..-1] + sequence[0..my_index - 1]

    target_seq_row = find_in_range(wrapped_range, target_color)

    return output, target_seq_row
  end
end