Class: Decidim::Attachment

Inherits:
ApplicationRecord show all
Defined in:
app/models/decidim/attachment.rb

Overview

Attachment can be any type of document or images related to a partcipatory process.

Instance Method Summary collapse

Instance Method Details

#big_urlObject

The URL to download the a big version of the file. Only works with images.

Returns String.



53
54
55
56
# File 'app/models/decidim/attachment.rb', line 53

def big_url
  return unless photo?
  file.big.url
end

#document?Boolean

Whether this attachment is a document or not.

Returns Boolean.

Returns:

  • (Boolean)


26
27
28
# File 'app/models/decidim/attachment.rb', line 26

def document?
  !photo?
end

#file_typeObject

Which kind of file this is.

Returns String.



33
34
35
# File 'app/models/decidim/attachment.rb', line 33

def file_type
  file.url&.split(".")&.last&.downcase
end

#photo?Boolean

Whether this attachment is a photo or not.

Returns Boolean.

Returns:

  • (Boolean)


19
20
21
# File 'app/models/decidim/attachment.rb', line 19

def photo?
  @photo ||= content_type.start_with? "image"
end

#thumbnail_urlObject

The URL to download the thumbnail of the file. Only works with images.

Returns String.



45
46
47
48
# File 'app/models/decidim/attachment.rb', line 45

def thumbnail_url
  return unless photo?
  file.thumbnail.url
end