Class: SendWithUs::Attachment
- Inherits:
-
Object
- Object
- SendWithUs::Attachment
- Defined in:
- lib/send_with_us/attachment.rb
Instance Method Summary collapse
- #encoded_data ⇒ Object
- #filename ⇒ Object
-
#initialize(attachment, filename = nil) ⇒ Attachment
constructor
A new instance of Attachment.
- #to_h ⇒ Object
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 , filename = nil @attachment, @filename = , filename end |
Instance Method Details
#encoded_data ⇒ Object
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 |
#filename ⇒ Object
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_h ⇒ Object
16 17 18 19 |
# File 'lib/send_with_us/attachment.rb', line 16 def to_h { id: filename, data: encoded_data } end |