Add geozones as user segments

This commit is contained in:
rgarcia
2018-07-24 20:29:09 +02:00
committed by Javi Martín
parent 7a028411ab
commit 25a8950330
3 changed files with 110 additions and 9 deletions

View File

@@ -8,11 +8,11 @@ class UserSegments
feasible_and_undecided_investment_authors
selected_investment_authors
winner_investment_authors
not_supported_on_current_budget].freeze
not_supported_on_current_budget] + geozones.keys
end
def self.segment_name(segment)
I18n.t("admin.segment_recipient.#{segment}") if segments.include?(segment.to_s)
geozones[segment.to_s]&.name || I18n.t("admin.segment_recipient.#{segment}") if valid_segment?(segment)
end
def self.all_users
@@ -58,11 +58,15 @@ class UserSegments
end
def self.valid_segment?(segment)
segment && respond_to?(segment)
segments.include?(segment.to_s)
end
def self.recipients(segment)
send(segment)
if geozones[segment.to_s]
all_users.where(geozone: geozones[segment.to_s])
else
send(segment)
end
end
def self.user_segment_emails(segment)
@@ -78,4 +82,8 @@ class UserSegments
def self.author_ids(author_ids)
all_users.where(id: author_ids)
end
def self.geozones
Geozone.order(:name).map { |geozone| [geozone.name.parameterize.underscore, geozone] }.to_h
end
end