Class: BlabberMouth::Attachment
- Inherits:
-
Object
- Object
- BlabberMouth::Attachment
- Defined in:
- lib/blabber_mouth/attachment.rb
Overview
Creates an attachment for a BlabberMouth object.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns a String representing the body of the attachment.
-
#file_name ⇒ Object
Returns the name of the attached file.
Instance Method Summary collapse
-
#add_file(file) ⇒ Object
Takes a path to a file, reads it in, and sets the file_name based on the path.
-
#add_io(io) ⇒ Object
Takes an IO object and sets the body.
-
#initialize(body = nil) ⇒ Attachment
constructor
A new instance of Attachment.
Constructor Details
#initialize(body = nil) ⇒ Attachment
Returns a new instance of Attachment.
10 11 12 13 14 15 |
# File 'lib/blabber_mouth/attachment.rb', line 10 def initialize(body = nil) unless body.nil? self.add_file(body) if body.is_a?(String) self.add_io(body) if body.is_a?(IO) end end |
Instance Attribute Details
#body ⇒ Object
Returns a String representing the body of the attachment. This String is NOT encoded in anyway!
6 7 8 |
# File 'lib/blabber_mouth/attachment.rb', line 6 def body @body end |
#file_name ⇒ Object
Returns the name of the attached file.
8 9 10 |
# File 'lib/blabber_mouth/attachment.rb', line 8 def file_name @file_name end |
Instance Method Details
#add_file(file) ⇒ Object
Takes a path to a file, reads it in, and sets the file_name based on the path.
23 24 25 26 |
# File 'lib/blabber_mouth/attachment.rb', line 23 def add_file(file) self.file_name = File.basename(file) self.body = File.read(file) end |
#add_io(io) ⇒ Object
Takes an IO object and sets the body. You’ll need to explicity set the file_name afterwards.
18 19 20 |
# File 'lib/blabber_mouth/attachment.rb', line 18 def add_io(io) self.body = io.read end |