Class: MailToFriend
- Inherits:
-
Object
- Object
- MailToFriend
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/mail_to_friend.rb
Constant Summary collapse
- EMAILREGEX =
/^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,8}$/i
Instance Attribute Summary collapse
-
#hide_recipients ⇒ Object
Returns the value of attribute hide_recipients.
-
#invalid_recipients ⇒ Object
Returns the value of attribute invalid_recipients.
-
#message ⇒ Object
Returns the value of attribute message.
-
#recipient_email ⇒ Object
Returns the value of attribute recipient_email.
-
#recipient_name ⇒ Object
Returns the value of attribute recipient_name.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#sender_email ⇒ Object
Returns the value of attribute sender_email.
-
#sender_name ⇒ Object
Returns the value of attribute sender_name.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ MailToFriend
constructor
A new instance of MailToFriend.
- #is_multi ⇒ Object
- #persisted? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ MailToFriend
Returns a new instance of MailToFriend.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/mail_to_friend.rb', line 15 def initialize(opts = {}) @subject = opts[:subject] || I18n.t('email_to_friend.you_would_like_this') @sender_email = opts[:sender_email] || ' ' @sender_name = opts[:sender_name] || @sender_email.split('@', 2)[0].titleize @recipients = [] @invalid_recipients = [] @recipient_email = (opts[:recipient_email] || '').gsub(';', ',').gsub(/\s/ , '') @recipient_email.split(',').each do |address| if address =~ EMAILREGEX @recipients << address else @invalid_recipients << address end end @recipient_name = opts[:recipient_name] @recipient_name ||= @recipients[0].split('@', 2)[0].titleize unless @recipients.empty? @hide_recipients = opts[:hide_recipients] || false @message = opts[:message] end |
Instance Attribute Details
#hide_recipients ⇒ Object
Returns the value of attribute hide_recipients.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def hide_recipients @hide_recipients end |
#invalid_recipients ⇒ Object
Returns the value of attribute invalid_recipients.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def invalid_recipients @invalid_recipients end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def @message end |
#recipient_email ⇒ Object
Returns the value of attribute recipient_email.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def recipient_email @recipient_email end |
#recipient_name ⇒ Object
Returns the value of attribute recipient_name.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def recipient_name @recipient_name end |
#recipients ⇒ Object
Returns the value of attribute recipients.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def recipients @recipients end |
#sender_email ⇒ Object
Returns the value of attribute sender_email.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def sender_email @sender_email end |
#sender_name ⇒ Object
Returns the value of attribute sender_name.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def sender_name @sender_name end |
#subject ⇒ Object
Returns the value of attribute subject.
4 5 6 |
# File 'app/models/mail_to_friend.rb', line 4 def subject @subject end |
Instance Method Details
#is_multi ⇒ Object
43 44 45 |
# File 'app/models/mail_to_friend.rb', line 43 def is_multi (@recipients.size + @invalid_recipients.size) > 1 end |
#persisted? ⇒ Boolean
39 40 41 |
# File 'app/models/mail_to_friend.rb', line 39 def persisted? false end |