Class: Immobilienscout24::Helper::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/immobilienscout24/helper/attachment.rb

Overview

Basic helper for Immobilienscout24 attachments. Will try to extract mime type and filename for you.

This helper won’t work for files without a file extension. (e.g. ‘my_picture’ instead of ‘my_picture.jpg’)

If you have files without an extension you can build this helper class on your own:

Examples:


Immobilienscout24::Helper::Attachment.new({
  file: 'path/to/file',
  content_type: 'image/jpeg',
  filename: 'estate.jpg',
  file_extension: '.jpg'
})

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment) ⇒ Attachment

Returns a new instance of Attachment.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/immobilienscout24/helper/attachment.rb', line 28

def initialize(attachment)
  case attachment
  when Hash
    @file, @content_type = attachment[:file], attachment[:content_type]
    @filename, @file_extension = attachment[:filename], attachment[:file_extension]
  when Array
    @file, @content_type, @filename, @file_extension = attachment
  when String
    @file = attachment
  when File
    @file = attachment.path
  when Immobilienscout24::Helper::Attachment
    helper = attachment
    @file, @content_type, @filename = helper.build
    @file_extension = helper.file_extension
  end
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



24
25
26
# File 'lib/immobilienscout24/helper/attachment.rb', line 24

def content_type
  @content_type
end

#fileObject

Returns the value of attribute file.



23
24
25
# File 'lib/immobilienscout24/helper/attachment.rb', line 23

def file
  @file
end

#file_extensionObject

Returns the value of attribute file_extension.



26
27
28
# File 'lib/immobilienscout24/helper/attachment.rb', line 26

def file_extension
  @file_extension
end

#filenameObject

Returns the value of attribute filename.



25
26
27
# File 'lib/immobilienscout24/helper/attachment.rb', line 25

def filename
  @filename
end

Class Method Details

.mime_typesObject



62
63
64
65
66
67
68
69
70
# File 'lib/immobilienscout24/helper/attachment.rb', line 62

def self.mime_types
  {
    ".jpg"  => "image/jpeg",
    ".jpeg" => "image/jpeg",
    ".gif"  => "image/gif",
    ".png"  => "image/png",
    ".pdf"  => "application/pdf"
  }
end

Instance Method Details

#buildObject



46
47
48
# File 'lib/immobilienscout24/helper/attachment.rb', line 46

def build
  [file, content_type, filename]
end