Class: SendWithUs::Attachment

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

Instance Method Summary collapse

Constructor Details

#initialize(attachment, filename = nil) ⇒ Attachment

Returns a new instance of Attachment.



3
4
5
# File 'lib/send_with_us/attachment.rb', line 3

def initialize attachment, filename = nil
  @attachment, @filename = attachment, filename
end

Instance Method Details

#encoded_dataObject



11
12
13
14
# File 'lib/send_with_us/attachment.rb', line 11

def encoded_data
  file_data = @attachment.respond_to?(:read) ? @attachment : open(@attachment)
  Base64.encode64(file_data.read)
end

#filenameObject



7
8
9
# File 'lib/send_with_us/attachment.rb', line 7

def filename
  @filename ||= @attachment.is_a?(String) ? ::File.basename(@attachment) : nil
end

#to_hObject



16
17
18
19
# File 'lib/send_with_us/attachment.rb', line 16

def to_h
  { id: filename,
    data: encoded_data }
end