Class: BlabberMouth::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/blabber_mouth/attachment.rb

Overview

Creates an attachment for a BlabberMouth object.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject

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_nameObject

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