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

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

Overview

Sequence

Class Method Summary collapse

Class Method Details

.ById(output, id) ⇒ Object

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



88
89
90
91
92
93
94
95
# File 'lib/trailblazer/activity/dsl/linear.rb', line 88

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

.find_in_range(range, target_color) ⇒ Object



98
99
100
# File 'lib/trailblazer/activity/dsl/linear.rb', line 98

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.



59
60
61
62
63
64
65
# File 'lib/trailblazer/activity/dsl/linear.rb', line 59

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) ⇒ Object



81
82
83
84
85
# File 'lib/trailblazer/activity/dsl/linear.rb', line 81

def Noop(output)
  ->(sequence, me) do
    return output, [nil,nil,nil,{}] # FIXME
  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.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/trailblazer/activity/dsl/linear.rb', line 69

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