Class: Spree::MailToCloud

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/spree/mail_to_cloud.rb

Constant Summary collapse

EMAILREGEX =
/[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,8}/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MailToCloud

Returns a new instance of MailToCloud.



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/spree/mail_to_cloud.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_recipientsObject

Returns the value of attribute hide_recipients.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def hide_recipients
  @hide_recipients
end

#invalid_recipientsObject

Returns the value of attribute invalid_recipients.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def invalid_recipients
  @invalid_recipients
end

#messageObject

Returns the value of attribute message.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def message
  @message
end

#recipient_emailObject

Returns the value of attribute recipient_email.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def recipient_email
  @recipient_email
end

#recipient_nameObject

Returns the value of attribute recipient_name.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def recipient_name
  @recipient_name
end

#recipientsObject

Returns the value of attribute recipients.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def recipients
  @recipients
end

#sender_emailObject

Returns the value of attribute sender_email.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def sender_email
  @sender_email
end

#sender_nameObject

Returns the value of attribute sender_name.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def sender_name
  @sender_name
end

#subjectObject

Returns the value of attribute subject.



4
5
6
# File 'app/models/spree/mail_to_cloud.rb', line 4

def subject
  @subject
end

Instance Method Details

#is_multiObject



43
44
45
# File 'app/models/spree/mail_to_cloud.rb', line 43

def is_multi
  (@recipients.size + @invalid_recipients.size) > 1
end

#persisted?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/spree/mail_to_cloud.rb', line 39

def persisted?
  false
end