From 69bc5b8363d944836fe13cf3ca1944b898a2e329 Mon Sep 17 00:00:00 2001 From: Jack S Date: Thu, 9 Feb 2023 12:24:43 +0000 Subject: [PATCH] Refactor formhandler --- app/models/form_handler.rb | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 15ec6b8fd..8f34288b3 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -3,6 +3,19 @@ class FormHandler include CollectionTimeHelper attr_reader :forms + SALES_SECTIONS = [ + Form::Sales::Sections::PropertyInformation, + Form::Sales::Sections::Household, + Form::Sales::Sections::Finances, + Form::Sales::Sections::SaleInformation, + ].freeze + + LETTINGS_SECTIONS = [ + Form::Lettings::Sections::TenancyAndProperty, + Form::Lettings::Sections::Household, + Form::Lettings::Sections::RentAndCharges, + ].freeze + def initialize @forms = get_all_forms end @@ -20,18 +33,11 @@ class FormHandler end def sales_forms - sales_sections = [ - Form::Sales::Sections::PropertyInformation, - Form::Sales::Sections::Household, - Form::Sales::Sections::Finances, - Form::Sales::Sections::SaleInformation, - ] - current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales") - previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales") - next_form = Form.new(nil, current_collection_start_year + 1, sales_sections, "sales") - { "current_sales" => current_form, - "previous_sales" => previous_form, - "next_sales" => next_form } + { + "current_sales" => Form.new(nil, current_collection_start_year, SALES_SECTIONS, "sales"), + "previous_sales" => Form.new(nil, current_collection_start_year - 1, SALES_SECTIONS, "sales"), + "next_sales" => Form.new(nil, current_collection_start_year + 1, SALES_SECTIONS, "sales"), + } end def lettings_forms @@ -45,17 +51,11 @@ class FormHandler end end - lettings_sections = [ - Form::Lettings::Sections::TenancyAndProperty, - Form::Lettings::Sections::Household, - Form::Lettings::Sections::RentAndCharges, - ] - if forms["previous_lettings"].blank? && current_collection_start_year >= 2022 - forms["previous_lettings"] = Form.new(nil, current_collection_start_year - 1, lettings_sections, "lettings") + forms["previous_lettings"] = Form.new(nil, current_collection_start_year - 1, LETTINGS_SECTIONS, "lettings") end - forms["current_lettings"] = Form.new(nil, current_collection_start_year, lettings_sections, "lettings") if forms["current_lettings"].blank? - forms["next_lettings"] = Form.new(nil, current_collection_start_year + 1, lettings_sections, "lettings") if forms["next_lettings"].blank? + forms["current_lettings"] = Form.new(nil, current_collection_start_year, LETTINGS_SECTIONS, "lettings") if forms["current_lettings"].blank? + forms["next_lettings"] = Form.new(nil, current_collection_start_year + 1, LETTINGS_SECTIONS, "lettings") if forms["next_lettings"].blank? forms end