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.



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

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

Instance Method Details

#==(other) ⇒ Object



273
274
275
# File 'lib/astrotrain/message.rb', line 273

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

#attached?Boolean

Returns:

  • (Boolean)


269
270
271
# File 'lib/astrotrain/message.rb', line 269

def attached?
  !filename.nil?
end

#closeObject

For IO API compatibility when used with Rest-Client



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

def close
end

#content_typeObject



238
239
240
# File 'lib/astrotrain/message.rb', line 238

def content_type
  @part.content_type
end

#dataObject



265
266
267
# File 'lib/astrotrain/message.rb', line 265

def data
  @part.body
end

#filenameObject Also known as: path



242
243
244
# File 'lib/astrotrain/message.rb', line 242

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

#inspectObject



277
278
279
# File 'lib/astrotrain/message.rb', line 277

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

#read(value = nil) ⇒ Object



252
253
254
255
256
257
258
259
# File 'lib/astrotrain/message.rb', line 252

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

#read?Boolean

Returns:

  • (Boolean)


261
262
263
# File 'lib/astrotrain/message.rb', line 261

def read?
  @is_read == true
end