From 048db88d47ffb26fbeeb4016608c83fa9debe3cf Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 5 May 2022 09:19:15 +0100 Subject: [PATCH] Refactor ecstat age check --- app/models/case_log.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index b8bbfd0b0..68cbef3ac 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -475,14 +475,18 @@ private end end (2..8).each do |idx| - if public_send("age#{idx}") && public_send("age#{idx}") < 16 + if age_under_16?(idx) self["ecstat#{idx}"] = 9 - elsif public_send("ecstat#{idx}") == 9 && (public_send("age#{idx}").nil? || public_send("age#{idx}") >= 16) && age_known?(idx) + elsif public_send("ecstat#{idx}") == 9 && age_known?(idx) self["ecstat#{idx}"] = nil end end end + def age_under_16?(person_num) + public_send("age#{person_num}") && public_send("age#{person_num}") < 16 + end + def age_known?(person_num) !!public_send("age#{person_num}_known")&.zero? end