From 5c88c1cf9c1b8b027d4530c5b5a833f9be762f35 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 20 Nov 2023 16:09:28 +0000 Subject: [PATCH] Simplify formatted_local_authority_timeline --- app/helpers/locations_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 5a3b0fb24..f718e9576 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -28,7 +28,7 @@ module LocationsHelper { name: "Postcode", value: location.postcode, attribute: "postcode" }, { name: "Location name", value: location.name, attribute: "name" }, { name: "Status", value: location.status, attribute: "status" }, - { name: "Local authority", value: formatted_local_authority_timeline(location, "name"), attribute: "local_authority" }, + { name: "Local authority", value: formatted_local_authority_timeline(location), attribute: "local_authority" }, { name: "Number of units", value: location.units, attribute: "units" }, { name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" }, { name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" }, @@ -41,7 +41,7 @@ module LocationsHelper [ { name: "Postcode", value: location.postcode, attribute: "postcode" }, { name: "Location name", value: location.name, attribute: "name" }, - { name: "Local authority", value: formatted_local_authority_timeline(location, "name"), attribute: "local_authority" }, + { name: "Local authority", value: formatted_local_authority_timeline(location), attribute: "local_authority" }, { name: "Number of units", value: location.units, attribute: "units" }, { name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" }, { name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" }, @@ -121,14 +121,14 @@ private [inner.deactivation_date, inner.reactivation_date].all? { |date| date.between?(outer.deactivation_date, outer.reactivation_date) } end - def formatted_local_authority_timeline(location, field) + def formatted_local_authority_timeline(location) sorted_linked_authorities = location.linked_local_authorities.sort_by(&:start_date) - return sorted_linked_authorities.first[field] if sorted_linked_authorities.count == 1 + return sorted_linked_authorities.first["name"] if sorted_linked_authorities.count == 1 sorted_linked_authorities.map { |linked_local_authority| formatted_start_date = linked_local_authority.start_date.year == 2021 ? "until" : "#{linked_local_authority.start_date&.to_formatted_s(:govuk_date)} -" formatted_end_date = linked_local_authority.end_date&.to_formatted_s(:govuk_date) || "present" - "#{linked_local_authority[field]} (#{formatted_start_date} #{formatted_end_date})" + "#{linked_local_authority['name']} (#{formatted_start_date} #{formatted_end_date})" }.join("\n") end end