I'm trying to respect the ruby principle of keeping my code dry; however, in my conditional, I have different constants set to different days. But that's the only thing different. They're pretty much the same code minus the evaluation of days from_now.
if term_type == TERM_MONTH
subscription.suspended_at && subscription.suspended_at < MONTHLY_WARNING_1.from_now && suspended_email_1_sent_at.nil? && subscription.suspended_at >= Date.today && is_system == true && paid_at.nil?
else
subscription.suspended_at && subscription.suspended_at < ANNUAL_WARNING_1.from_now && suspended_email_1_sent_at.nil? && subscription.suspended_at >= Date.today && is_system == true && paid_at.nil?
end
I tried using the ternary operator; however, it didn't produce the results I was expecting as it was only setting the days based on term_type yet not sending the mail based on it.
days = term_type == TERM_MONTH ? MONTHLY_WARNING_1 : ANNUAL_WARNING_1
subscription.suspended_at && subscription.suspended_at < days.from_now && suspended_email_1_sent_at.nil? && subscription.suspended_at >= Date.today && is_system == true && paid_at.nil?
A point in the right direction will be helpful. TIA.
Aucun commentaire:
Enregistrer un commentaire