Skip to content

Instantly share code, notes, and snippets.

@joeljackson
Created August 7, 2015 18:24
Show Gist options
  • Save joeljackson/ae224cf45b93e7b46511 to your computer and use it in GitHub Desktop.
Save joeljackson/ae224cf45b93e7b46511 to your computer and use it in GitHub Desktop.
EMAIL_PREFERENCES = %w[baby_weight_update_requests in_on_and_around_your_baby nursery marketing_email]
def wants_email?(email_preference)
email_preferences.include?(email_preference.to_s)
end
def email_preferences=(email_preferences)
self.email_preferences_mask =
(email_preferences.map!{|p| p.to_s} & EMAIL_PREFERENCES).map { |p| 2**EMAIL_PREFERENCES.index(p) }.sum
end
def email_preferences
EMAIL_PREFERENCES.reject do |p|
((email_preferences_mask || 0) & 2**EMAIL_PREFERENCES.index(p)).zero?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment