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


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

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

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

  @original_filename = @filename

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

  @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!(mb) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/railgun/attachment.rb', line 43

def attach_to_message!(mb)
  if mb.nil?
    nil
  end

  if inline?
    mb.add_inline_image self, @filename
  else
    mb.add_attachment self, @filename
  end
end

#inline?Boolean


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

def inline?
  @inline
end

#is_original_filenameObject


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

def is_original_filename
  @original_filename == @overwritten_filename
end

#source_filenameObject


39
40
41
# File 'lib/railgun/attachment.rb', line 39

def source_filename
  @filename
end