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.



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

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

#document?Boolean

Whether this attachment is a document or not.

Returns Boolean.

Returns:

  • (Boolean)


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

def document?
  !photo?
end

#file_typeObject

Which kind of file this is.

Returns String.



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

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

#photo?Boolean

Whether this attachment is a photo or not.

Returns Boolean.

Returns:

  • (Boolean)


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

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.



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

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