From f004d3cc6f8d530f31c9faf1226c86e732d8a39d Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 14 Dec 2022 16:11:41 +0000 Subject: [PATCH] refactor indexes --- .../questions/person_working_situation.rb | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/app/models/form/sales/questions/person_working_situation.rb b/app/models/form/sales/questions/person_working_situation.rb index 728153d8c..40ca59ec5 100644 --- a/app/models/form/sales/questions/person_working_situation.rb +++ b/app/models/form/sales/questions/person_working_situation.rb @@ -1,12 +1,12 @@ class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question def initialize(id, hsh, page) super - @check_answer_label = "Person #{PERSON_INDEX[page.id]}’s working situation" - @header = "Which of these best describes Person #{PERSON_INDEX[page.id]}’s working situation?" + @check_answer_label = "Person #{person_display_number}’s working situation" + @header = "Which of these best describes Person #{person_display_number}’s working situation?" @type = "radio" @page = page @answer_options = ANSWER_OPTIONS - @check_answers_card_number = CARD_INDEX[page.id] + @check_answers_card_number = person_database_number end ANSWER_OPTIONS = { @@ -23,25 +23,23 @@ class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question "9" => { "value" => "Child under 16" }, }.freeze - CARD_INDEX = { - "person_1_working_situation" => 2, - "person_1_working_situation_joint_purchase" => 3, - "person_2_working_situation" => 3, - "person_2_working_situation_joint_purchase" => 4, - "person_3_working_situation" => 4, - "person_3_working_situation_joint_purchase" => 5, - "person_4_working_situation" => 5, - "person_4_working_situation_joint_purchase" => 6, - }.freeze + def person_database_number + PERSON_INDEX[id] + end PERSON_INDEX = { - "person_1_working_situation" => 1, - "person_1_working_situation_joint_purchase" => 1, - "person_2_working_situation" => 2, - "person_2_working_situation_joint_purchase" => 2, - "person_3_working_situation" => 3, - "person_3_working_situation_joint_purchase" => 3, - "person_4_working_situation" => 4, - "person_4_working_situation_joint_purchase" => 4, + "ecstat2" => 2, + "ecstat3" => 3, + "ecstat4" => 4, + "ecstat5" => 5, + "ecstat6" => 6, }.freeze + + def person_display_number + joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1 + end + + def joint_purchase? + page.id.include?("_joint_purchase") + end end