Class: Immobilienscout24::Helper::Attachment
- Inherits:
-
Object
- Object
- Immobilienscout24::Helper::Attachment
- 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:
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#file ⇒ Object
Returns the value of attribute file.
-
#file_extension ⇒ Object
Returns the value of attribute file_extension.
-
#filename ⇒ Object
Returns the value of attribute filename.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(attachment) ⇒ Attachment
constructor
A new instance of Attachment.
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() case when Hash @file, @content_type = [:file], [:content_type] @filename, @file_extension = [:filename], [:file_extension] when Array @file, @content_type, @filename, @file_extension = when String @file = when File @file = .path when Immobilienscout24::Helper::Attachment helper = @file, @content_type, @filename = helper.build @file_extension = helper.file_extension end end |
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
24 25 26 |
# File 'lib/immobilienscout24/helper/attachment.rb', line 24 def content_type @content_type end |
#file ⇒ Object
Returns the value of attribute file.
23 24 25 |
# File 'lib/immobilienscout24/helper/attachment.rb', line 23 def file @file end |
#file_extension ⇒ Object
Returns the value of attribute file_extension.
26 27 28 |
# File 'lib/immobilienscout24/helper/attachment.rb', line 26 def file_extension @file_extension end |
#filename ⇒ Object
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_types ⇒ Object
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
#build ⇒ Object
46 47 48 |
# File 'lib/immobilienscout24/helper/attachment.rb', line 46 def build [file, content_type, filename] end |