Class: Astrotrain::Message::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/astrotrain/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(part) ⇒ Attachment

Returns a new instance of Attachment.



219
220
221
222
# File 'lib/astrotrain/message.rb', line 219

def initialize(part)
  @part    = part
  @is_read = false
end

Instance Method Details

#==(other) ⇒ Object



259
260
261
# File 'lib/astrotrain/message.rb', line 259

def ==(other)
  super || (filename == other.filename && content_type == other.content_type)
end

#attached?Boolean

Returns:

  • (Boolean)


255
256
257
# File 'lib/astrotrain/message.rb', line 255

def attached?
  !filename.nil?
end

#closeObject

For IO API compatibility when used with Rest-Client



233
234
# File 'lib/astrotrain/message.rb', line 233

def close
end

#content_typeObject



224
225
226
# File 'lib/astrotrain/message.rb', line 224

def content_type
  @part.content_type
end

#dataObject



251
252
253
# File 'lib/astrotrain/message.rb', line 251

def data
  @part.body
end

#filenameObject Also known as: path



228
229
230
# File 'lib/astrotrain/message.rb', line 228

def filename
  @filename ||= @part.type_param("name") || @part.disposition_param('filename')
end

#inspectObject



263
264
265
# File 'lib/astrotrain/message.rb', line 263

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

#read(value = nil) ⇒ Object



238
239
240
241
242
243
244
245
# File 'lib/astrotrain/message.rb', line 238

def read(value = nil)
  if read?
    nil
  else
    @is_read = true
    data
  end
end

#read?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/astrotrain/message.rb', line 247

def read?
  @is_read == true
end