Class: Astrotrain::Attachment

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/astrotrain/attachment.rb', line 43

def attached?
  !filename.nil?
end

#content_typeObject



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

def content_type
  @part.content_type
end

#dataObject



35
36
37
# File 'lib/astrotrain/attachment.rb', line 35

def data
  @data ||= @part.body.to_s
end

#filenameObject Also known as: local_path, original_filename



15
16
17
# File 'lib/astrotrain/attachment.rb', line 15

def filename
  @part.filename
end

#inspectObject



51
52
53
# File 'lib/astrotrain/attachment.rb', line 51

def inspect
  %(#<Message::Attachment filename=#{filename.inspect} content_type=#{content_type.inspect}>)
end

#lengthObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/astrotrain/attachment.rb', line 31

def read?
  @is_read == true
end