Created
August 7, 2015 18:24
-
-
Save joeljackson/ae224cf45b93e7b46511 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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