docbrown/app/mailers/digest_mailer.rb
Ben Halpern c93bc48010
Fix issue with boosted article in email digest (#1936)
* Adjust email digest

* Fix for missing user.experience_level

* Fix direction of greater than

* Adjust tests for new criteria
2019-03-01 13:51:06 -08:00

50 lines
1.5 KiB
Ruby

class DigestMailer < ApplicationMailer
default from: "DEV Digest <yo@dev.to>"
def digest_email(user, articles)
@user = user
@articles = articles.first(6)
@unsubscribe = generate_unsubscribe_token(@user.id, :email_digest_periodic)
subject = generate_title
mail(to: @user.email, subject: subject)
end
private
def generate_title
"#{adjusted_title(@articles.first)} + #{@articles.size - 1} #{email_end_phrase} #{random_emoji}"
end
def adjusted_title(article)
title = article.title.strip
"\"#{title}\"" unless title.start_with? '"'
end
def random_emoji
["🤓", "🎉", "🙈", "🔥", "💬", "👋", "👏", "🐶", "🦁", "🐙", "🦄", "❤️", "😇"].shuffle.take(3).join
end
def email_end_phrase
# "more trending DEV posts" won the previous split test
# Included more often as per explore-exploit algorithm
[
"more trending DEV posts",
"more trending DEV posts",
"more trending DEV posts",
"more trending DEV posts",
"more trending DEV posts",
"more trending DEV posts",
"more trending DEV posts",
"more trending DEV posts",
"more trending DEV posts",
"other posts you might like",
"other DEV posts you might like",
"other trending DEV posts",
"other top DEV posts",
"more top DEV posts",
"more top reads from the community",
"more top DEV posts based on your interests",
"more trending DEV posts picked for you",
].sample
end
end