Class: GmailMailer::Message
- Inherits:
-
Object
- Object
- GmailMailer::Message
- Defined in:
- lib/gmail-mailer.rb
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#body ⇒ Object
Returns the value of attribute body.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #add_attachment(filepath) ⇒ Object
- #get_attachments_size ⇒ Object
-
#initialize(to, subject = "", body = "") ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(to, subject = "", body = "") ⇒ Message
Returns a new instance of Message.
78 79 80 81 82 83 |
# File 'lib/gmail-mailer.rb', line 78 def initialize(to, subject="", body="") self.to=(to) @subject = subject @body = body @attachments = [] end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
77 78 79 |
# File 'lib/gmail-mailer.rb', line 77 def @attachments end |
#body ⇒ Object
Returns the value of attribute body.
76 77 78 |
# File 'lib/gmail-mailer.rb', line 76 def body @body end |
#subject ⇒ Object
Returns the value of attribute subject.
76 77 78 |
# File 'lib/gmail-mailer.rb', line 76 def subject @subject end |
#to ⇒ Object
Returns the value of attribute to.
77 78 79 |
# File 'lib/gmail-mailer.rb', line 77 def to @to end |
Instance Method Details
#add_attachment(filepath) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/gmail-mailer.rb', line 85 def (filepath) raise ArgumentError, "You must specify a file to send" if filepath.nil? or filepath.empty? raise ArgumentError, "File #{filepath} does not exist" if !File.exist?(filepath) raise ArgumentError, "#{filepath} file is a directory, this is not supported" if File.directory?(filepath) size = File.size(filepath) print "Adding attachment: #{filepath} " printf("(%5.4f kb)",size.to_f/1024.0) puts raise ArgumentError, "There is a #{ATTACHMENTS_SIZE_LIMIT/1024/1024}mb limit on attachments}" if ( + size) > ATTACHMENTS_SIZE_LIMIT @attachments << filepath end |
#get_attachments_size ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/gmail-mailer.rb', line 105 def = 0 @attachments.each do || += File.size() end return end |