Class: Astrotrain::Attachment
- Inherits:
-
Object
- Object
- Astrotrain::Attachment
- Defined in:
- lib/astrotrain/attachment.rb
Overview
Simple class that wraps a TMail part attachment in the IO API for Faraday
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attached? ⇒ Boolean
- #content_type ⇒ Object
- #data ⇒ Object
- #filename ⇒ Object (also: #local_path, #original_filename)
-
#initialize(part) ⇒ Attachment
constructor
A new instance of Attachment.
- #inspect ⇒ Object
- #length ⇒ Object
- #read(value = nil) ⇒ Object
- #read? ⇒ Boolean
Constructor Details
#initialize(part) ⇒ Attachment
Returns a new instance of Attachment.
5 6 7 8 9 |
# File 'lib/astrotrain/attachment.rb', line 5 def initialize(part) @data = nil @part = part @is_read = false end |
Instance Method Details
#==(other) ⇒ Object
47 48 49 |
# File 'lib/astrotrain/attachment.rb', line 47 def ==(other) super || (filename == other.filename && content_type == other.content_type) end |
#attached? ⇒ Boolean
43 44 45 |
# File 'lib/astrotrain/attachment.rb', line 43 def attached? !filename.nil? end |
#content_type ⇒ Object
11 12 13 |
# File 'lib/astrotrain/attachment.rb', line 11 def content_type @part.content_type end |
#data ⇒ Object
35 36 37 |
# File 'lib/astrotrain/attachment.rb', line 35 def data @data ||= @part.body.to_s end |
#filename ⇒ Object Also known as: local_path, original_filename
15 16 17 |
# File 'lib/astrotrain/attachment.rb', line 15 def filename @part.filename end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/astrotrain/attachment.rb', line 51 def inspect %(#<Message::Attachment filename=#{filename.inspect} content_type=#{content_type.inspect}>) end |
#length ⇒ Object
39 40 41 |
# File 'lib/astrotrain/attachment.rb', line 39 def length data.size end |
#read(value = nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/astrotrain/attachment.rb', line 22 def read(value = nil) if read? nil else @is_read = true data end end |
#read? ⇒ Boolean
31 32 33 |
# File 'lib/astrotrain/attachment.rb', line 31 def read? @is_read == true end |