Skip to content

Commit

Permalink
convert check-uk-visa study and work flow blocks to lambdas
Browse files Browse the repository at this point in the history
- working around the edges of ruby method structures
  • Loading branch information
FelixMarcusMillne committed Sep 20, 2023
1 parent 2a73cae commit 88427b2
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions app/flows/check_uk_visa_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def define
next_node do
if calculator.passing_through_uk_border_control? && calculator.passport_country_is_taiwan?
outcome :outcome_transit_taiwan_through_border_control
elsif calculator.passing_through_uk_border_control? && requires_a_visitor_in_transit_visa?
elsif calculator.passing_through_uk_border_control? && calculator.requires_a_visitor_in_transit_visa?
outcome :outcome_transit_leaving_airport
elsif calculator.passing_through_uk_border_control? && calculator.requires_a_direct_airside_transit_visa?
outcome :outcome_transit_leaving_airport_direct_airside_transit_visa
Expand Down Expand Up @@ -171,10 +171,14 @@ def define
end

next_node do
if calculator.study_visit?
flow.outcome_study_visit
if calculator.work_visit? && calculator.staying_for_over_six_months?
question :what_type_of_work?
elsif calculator.work_visit?
flow.next_node_for_work_visit
work_outcome = flow.work_visit_outcome_lambda.call calculator
outcome work_outcome unless work_outcome == nil

Check failure on line 178 in app/flows/check_uk_visa_flow.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/NilComparison: Prefer the use of the `nil?` predicate. (https://rubystyle.guide#predicate-methods)
elsif calculator.study_visit?
study_outcome = flow.study_visit_lambda.call calculator
outcome study_outcome unless study_outcome == nil

Check failure on line 181 in app/flows/check_uk_visa_flow.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/NilComparison: Prefer the use of the `nil?` predicate. (https://rubystyle.guide#predicate-methods)
end
end
end
Expand Down Expand Up @@ -355,36 +359,43 @@ def travel_response_next_route(node)
end
end

private


def next_node_for_work_visit
if calculator.staying_for_over_six_months?
question :what_type_of_work?
elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
outcome :outcome_work_waiver
elsif calculator.staying_for_six_months_or_less? && calculator.short_work_visits_are_approved?
# outcome 5.5 work N no visa needed
outcome :outcome_work_n
elsif calculator.staying_for_six_months_or_less?
# outcome 5 work m visa needed short courses
outcome :outcome_work_m
end
def study_visit_lambda
lambda { |calculator|
if calculator.staying_for_over_six_months?

Check failure on line 364 in app/flows/check_uk_visa_flow.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
outcome = :outcome_study_y # outcome 2 study y
elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
outcome = :outcome_study_waiver
elsif calculator.staying_for_six_months_or_less? && calculator.passport_country_is_taiwan?
outcome = :outcome_study_waiver_taiwan
elsif calculator.staying_for_six_months_or_less? && (calculator.requires_a_direct_airside_transit_visa? ||
calculator.passport_country_in_visa_national_list? ||
calculator.travel_document?)
outcome = :outcome_study_m # outcome 3 study m visa needed short courses
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?)
outcome = :outcome_study_no_visa_needed # outcome 1 no visa needed
else
outcome = nil
end
return outcome
}
end

def outcome_study_visit
if calculator.staying_for_over_six_months?
outcome :outcome_study_y # outcome 2 study y
elsif calculator.staying_for_six_months_or_less? && calculator.has_passport_requiring_electronic_visa_waiver_list?
outcome :outcome_study_waiver
elsif calculator.staying_for_six_months_or_less? && calculator.passport_country_is_taiwan?
outcome :outcome_study_waiver_taiwan
elsif calculator.staying_for_six_months_or_less? && (calculator.requires_a_direct_airside_transit_visa? ||
calculator.passport_country_in_visa_national_list? ||
calculator.travel_document?)
outcome :outcome_study_m # outcome 3 study m visa needed short courses
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?)
outcome :outcome_study_no_visa_needed # outcome 1 no visa needed
end
def work_visit_outcome_lambda
lambda { |calculator|
if calculator.staying_for_six_months_or_less? &&

Check failure on line 385 in app/flows/check_uk_visa_flow.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
calculator.has_passport_requiring_electronic_visa_waiver_list?

Check failure on line 386 in app/flows/check_uk_visa_flow.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/MultilineOperationIndentation: Use 4 (not 2) spaces for indenting a condition in an `if` statement spanning multiple lines.
outcome = :outcome_work_waiver
elsif calculator.staying_for_six_months_or_less? &&
calculator.short_work_visits_are_approved?

Check failure on line 389 in app/flows/check_uk_visa_flow.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/MultilineOperationIndentation: Use 4 (not 2) spaces for indenting a condition in a `elsif` statement spanning multiple lines.
# outcome 5.5 work N no visa needed
outcome = :outcome_work_n
elsif calculator.staying_for_six_months_or_less?
# outcome 5 work m visa needed short courses
outcome = :outcome_work_m
else
outcome = nil
end
return outcome
}
end
end

0 comments on commit 88427b2

Please sign in to comment.