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