Class: SendGrid::Email
- Inherits:
-
Object
- Object
- SendGrid::Email
- Defined in:
- lib/sendgrid/helpers/mail/email.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(email:, name: nil) ⇒ Email
constructor
A new instance of Email.
- #split_email(email) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(email:, name: nil) ⇒ Email
Returns a new instance of Email.
9 10 11 12 13 14 15 16 |
# File 'lib/sendgrid/helpers/mail/email.rb', line 9 def initialize(email:, name: nil) if name @email = email @name = name else @email, @name = split_email(email) end end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/sendgrid/helpers/mail/email.rb', line 5 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sendgrid/helpers/mail/email.rb', line 5 def name @name end |
Instance Method Details
#split_email(email) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/sendgrid/helpers/mail/email.rb', line 18 def split_email(email) split = /(?:(?<address>.+)\s)?<?(?<email>.+@[^>]+)>?/.match(email) raise ArgumentError, "email (#{email}) is invalid" unless split [split[:email], split[:address]] end |
#to_json ⇒ Object
25 26 27 28 29 30 |
# File 'lib/sendgrid/helpers/mail/email.rb', line 25 def to_json(*) { 'email' => email, 'name' => name }.delete_if { |_, value| value.to_s.strip == '' } end |