class SendWithUs::Attachment

Public Class Methods

new(attachment, filename = nil) click to toggle source
# File lib/send_with_us/attachment.rb, line 3
def initialize attachment, filename = nil
  @attachment, @filename = attachment, filename
end

Public Instance Methods

encoded_data() click to toggle source
# 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
filename() click to toggle source
# File lib/send_with_us/attachment.rb, line 7
def filename
  @filename ||= @attachment.is_a?(String) ? ::File.basename(@attachment) : nil
end
to_h() click to toggle source
# File lib/send_with_us/attachment.rb, line 16
def to_h
  { id: filename,
    data: encoded_data }
end