Class: Tenon::Asset

Inherits:
ApplicationRecord show all
Defined in:
app/models/tenon/asset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#crop_hObject

Returns the value of attribute crop_h.



3
4
5
# File 'app/models/tenon/asset.rb', line 3

def crop_h
  @crop_h
end

#crop_wObject

Returns the value of attribute crop_w.



3
4
5
# File 'app/models/tenon/asset.rb', line 3

def crop_w
  @crop_w
end

#crop_xObject

Returns the value of attribute crop_x.



3
4
5
# File 'app/models/tenon/asset.rb', line 3

def crop_x
  @crop_x
end

#crop_yObject

Returns the value of attribute crop_y.



3
4
5
# File 'app/models/tenon/asset.rb', line 3

def crop_y
  @crop_y
end

#duplicateObject

Returns the value of attribute duplicate.



3
4
5
# File 'app/models/tenon/asset.rb', line 3

def duplicate
  @duplicate
end

Class Method Details

.documentsObject



31
32
33
# File 'app/models/tenon/asset.rb', line 31

def self.documents
  where('attachment_content_type NOT LIKE ?', '%image%')
end

.with_type(type) ⇒ Object



23
24
25
26
27
28
29
# File 'app/models/tenon/asset.rb', line 23

def self.with_type(type)
  if %w(images).include?(type)
    where('attachment_content_type LIKE ?', "%#{type.singularize}%")
  else
    documents
  end
end

Instance Method Details

#cropping?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/tenon/asset.rb', line 45

def cropping?
  crop_x.present?
end

#dimensions(style = :original) ⇒ Object



39
40
41
42
43
# File 'app/models/tenon/asset.rb', line 39

def dimensions(style = :original)
  attach = style.to_sym == :original ? attachment : attachment.styles[style]
  file = Paperclip.io_adapters.for(attach)
  Paperclip::Geometry.from_file(file).to_s.split('x')
end

#is_image?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/tenon/asset.rb', line 35

def is_image?
  attachment_content_type =~ /image/
end