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.



51
52
53
54
# File 'app/models/decidim/attachment.rb', line 51

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

#document?Boolean

Whether this attachment is a document or not.

Returns Boolean.



22
23
24
# File 'app/models/decidim/attachment.rb', line 22

def document?
  !photo?
end

#file_typeObject

Which kind of file this is.

Returns String.



29
30
31
# File 'app/models/decidim/attachment.rb', line 29

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

#photo?Boolean

Whether this attachment is a photo or not.

Returns Boolean.



15
16
17
# File 'app/models/decidim/attachment.rb', line 15

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.



43
44
45
46
# File 'app/models/decidim/attachment.rb', line 43

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

#urlObject

The URL to download the file.

Returns String.



36
37
38
# File 'app/models/decidim/attachment.rb', line 36

def url
  file.url
end