From 8d3e31ee10e431c6bef73e530f6a1381dd2c81dd Mon Sep 17 00:00:00 2001 From: Milo Date: Tue, 26 Oct 2021 12:53:40 +0100 Subject: [PATCH] Update app/models/case_log.rb Use map rather than indexing Co-authored-by: Daniel Baark <5101747+baarkerlounger@users.noreply.github.com> --- app/models/case_log.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 7b8879026..cfdfca635 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -62,7 +62,11 @@ class CaseLogValidator < ActiveModel::Validator end end - p = 2 +(2..8).map do |n| + next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil? + + record["person_#{n}_gender"] == "Female" && record["person_#{n}_age"] >= 16 && record["person_#{n}_age"] <= 50 +end while p <= 8 unless record["person_#{p}_gender"].nil? || record["person_#{p}_age"].nil? if record["person_#{p}_gender"] == "Female" && record["person_#{p}_age"] >= 16 && record["person_#{p}_age"] <= 50