Class: Newman::MailingList
- Inherits:
-
Object
- Object
- Newman::MailingList
- Defined in:
- lib/newman/mailing_list.rb
Instance Method Summary collapse
-
#initialize(name, store) ⇒ MailingList
constructor
A new instance of MailingList.
- #subscribe(email) ⇒ Object
- #subscriber?(email) ⇒ Boolean
- #subscribers ⇒ Object
- #unsubscribe(email) ⇒ Object
Constructor Details
#initialize(name, store) ⇒ MailingList
Returns a new instance of MailingList.
3 4 5 6 |
# File 'lib/newman/mailing_list.rb', line 3 def initialize(name, store) self.name = name self.store = store end |
Instance Method Details
#subscribe(email) ⇒ Object
8 9 10 |
# File 'lib/newman/mailing_list.rb', line 8 def subscribe(email) store[name].create(email) end |
#subscriber?(email) ⇒ Boolean
17 18 19 |
# File 'lib/newman/mailing_list.rb', line 17 def subscriber?(email) store[name].any? { |r| r.contents == email } end |
#subscribers ⇒ Object
21 22 23 |
# File 'lib/newman/mailing_list.rb', line 21 def subscribers store[name].map { |r| r.contents } end |
#unsubscribe(email) ⇒ Object
12 13 14 15 |
# File 'lib/newman/mailing_list.rb', line 12 def unsubscribe(email) record = store[name].find { |e| e.contents == email } store[name].destroy(record.id) end |