Class: Railgun::Attachment

Inherits:
StringIO
  • Object
show all
Defined in:
lib/railgun/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment, *args) ⇒ Attachment

Returns a new instance of Attachment.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/railgun/attachment.rb', line 8

def initialize(attachment, *args)
  @path = ''
  @inline = args.detect { |opt| opt[:inline] }

  @filename = if @inline
                attachment.cid
              else
                attachment.filename
              end

  @original_filename = @filename

  @filename = opt[:filename] if args.detect { |opt| opt[:filename] }

  @overwritten_filename = @filename

  @content_type = attachment.content_type.split(';')[0]

  super attachment.body.decoded
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



5
6
7
# File 'lib/railgun/attachment.rb', line 5

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/railgun/attachment.rb', line 5

def filename
  @filename
end

#original_filenameObject (readonly)

Returns the value of attribute original_filename.



5
6
7
# File 'lib/railgun/attachment.rb', line 5

def original_filename
  @original_filename
end

#overwritten_filenameObject (readonly)

Returns the value of attribute overwritten_filename.



5
6
7
# File 'lib/railgun/attachment.rb', line 5

def overwritten_filename
  @overwritten_filename
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/railgun/attachment.rb', line 5

def path
  @path
end

Instance Method Details

#attach_to_message!(m_body) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/railgun/attachment.rb', line 41

def attach_to_message!(m_body)
  if inline?
    m_body.add_inline_image self, @filename
  else
    m_body.add_attachment self, @filename
  end
end

#inline?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/railgun/attachment.rb', line 29

def inline?
  @inline
end

#original_filename?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/railgun/attachment.rb', line 33

def original_filename?
  @original_filename == @overwritten_filename
end

#source_filenameObject



37
38
39
# File 'lib/railgun/attachment.rb', line 37

def source_filename
  @filename
end