Skip to content

Commit ae5d677

Browse files
convert check-uk-visa study and work flow blocks to lambdas
- working around the edges of ruby method structures
1 parent 2a73cae commit ae5d677

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

app/flows/check_uk_visa_flow.rb

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def define
143143
next_node do
144144
if calculator.passing_through_uk_border_control? && calculator.passport_country_is_taiwan?
145145
outcome :outcome_transit_taiwan_through_border_control
146-
elsif calculator.passing_through_uk_border_control? && requires_a_visitor_in_transit_visa?
146+
elsif calculator.passing_through_uk_border_control? && calculator.requires_a_visitor_in_transit_visa?
147147
outcome :outcome_transit_leaving_airport
148148
elsif calculator.passing_through_uk_border_control? && calculator.requires_a_direct_airside_transit_visa?
149149
outcome :outcome_transit_leaving_airport_direct_airside_transit_visa
@@ -171,10 +171,14 @@ def define
171171
end
172172

173173
next_node do
174-
if calculator.study_visit?
175-
flow.outcome_study_visit
174+
if calculator.work_visit? && calculator.staying_for_over_six_months?
175+
question :what_type_of_work?
176176
elsif calculator.work_visit?
177-
flow.next_node_for_work_visit
177+
work_outcome = flow.work_visit_outcome_lambda.call calculator
178+
outcome work_outcome unless nil?
179+
elsif calculator.study_visit?
180+
study_outcome = flow.study_visit_lambda.call calculator
181+
outcome study_outcome unless nil?
178182
end
179183
end
180184
end
@@ -355,36 +359,43 @@ def travel_response_next_route(node)
355359
end
356360
end
357361

358-
private
359-
360-
361-
def next_node_for_work_visit
362-
if calculator.staying_for_over_six_months?
363-
question :what_type_of_work?
364-
elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
365-
outcome :outcome_work_waiver
366-
elsif calculator.staying_for_six_months_or_less? && calculator.short_work_visits_are_approved?
367-
# outcome 5.5 work N no visa needed
368-
outcome :outcome_work_n
369-
elsif calculator.staying_for_six_months_or_less?
370-
# outcome 5 work m visa needed short courses
371-
outcome :outcome_work_m
372-
end
362+
def study_visit_lambda
363+
lambda { |calculator|
364+
if calculator.staying_for_over_six_months?
365+
outcome = :outcome_study_y # outcome 2 study y
366+
elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
367+
outcome = :outcome_study_waiver
368+
elsif calculator.staying_for_six_months_or_less? && calculator.passport_country_is_taiwan?
369+
outcome = :outcome_study_waiver_taiwan
370+
elsif calculator.staying_for_six_months_or_less? && (calculator.requires_a_direct_airside_transit_visa? ||
371+
calculator.passport_country_in_visa_national_list? ||
372+
calculator.travel_document?)
373+
outcome = :outcome_study_m # outcome 3 study m visa needed short courses
374+
elsif calculator.staying_for_six_months_or_less? && (calculator.passport_country_in_british_overseas_territories_list? || calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_eea?)
375+
outcome = :outcome_study_no_visa_needed # outcome 1 no visa needed
376+
else
377+
outcome = nil
378+
end
379+
return outcome
380+
}
373381
end
374382

375-
def outcome_study_visit
376-
if calculator.staying_for_over_six_months?
377-
outcome :outcome_study_y # outcome 2 study y
378-
elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
379-
outcome :outcome_study_waiver
380-
elsif calculator.staying_for_six_months_or_less? && calculator.passport_country_is_taiwan?
381-
outcome :outcome_study_waiver_taiwan
382-
elsif calculator.staying_for_six_months_or_less? && (calculator.requires_a_direct_airside_transit_visa? ||
383-
calculator.passport_country_in_visa_national_list? ||
384-
calculator.travel_document?)
385-
outcome :outcome_study_m # outcome 3 study m visa needed short courses
386-
elsif calculator.staying_for_six_months_or_less? && (calculator.passport_country_in_british_overseas_territories_list? || calculator.passport_country_in_non_visa_national_list? || calculator.passport_country_in_eea?)
387-
outcome :outcome_study_no_visa_needed # outcome 1 no visa needed
388-
end
383+
def work_visit_outcome_lambda
384+
lambda { |calculator|
385+
if calculator.staying_for_six_months_or_less? &&
386+
calculator.has_passport_requiring_electronic_visa_waiver_list?
387+
outcome = :outcome_work_waiver
388+
elsif calculator.staying_for_six_months_or_less? &&
389+
calculator.short_work_visits_are_approved?
390+
# outcome 5.5 work N no visa needed
391+
outcome = :outcome_work_n
392+
elsif calculator.staying_for_six_months_or_less?
393+
# outcome 5 work m visa needed short courses
394+
outcome = :outcome_work_m
395+
else
396+
outcome = nil
397+
end
398+
return outcome
399+
}
389400
end
390401
end

0 commit comments

Comments
 (0)