module Trailblazer::Activity::DSL::Linear::Search

Sequence

Public Instance Methods

ById(output, id) click to toggle source

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

# File lib/trailblazer/activity/dsl/linear.rb, line 91
def ById(output, id)
  ->(sequence, me) do
    index          = 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
Forward(output, target_color) click to toggle source

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.

# File lib/trailblazer/activity/dsl/linear.rb, line 62
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
Noop(output) click to toggle source
# File lib/trailblazer/activity/dsl/linear.rb, line 84
def Noop(output)
  ->(sequence, me) do
    return output, [nil,nil,nil,{}] # FIXME
  end
end
WrapAround(output, target_color) click to toggle source

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.

# File lib/trailblazer/activity/dsl/linear.rb, line 72
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
find_in_range(range, target_color) click to toggle source

@private

# File lib/trailblazer/activity/dsl/linear.rb, line 101
def find_in_range(range, target_color)
  _target_seq_row = range.find { |seq_row| seq_row[0] == target_color }
end