Module: Paperclip::Meta::Attachment

Defined in:
lib/paperclip-meta/attachment.rb

Instance Method Summary collapse

Instance Method Details

#aspect_ratio(style = default_style) ⇒ Object


34
35
36
# File 'lib/paperclip-meta/attachment.rb', line 34

def aspect_ratio(style = default_style)
  width(style).to_f / height(style).to_f
end

#assign_attributesObject


4
5
6
7
# File 'lib/paperclip-meta/attachment.rb', line 4

def assign_attributes
  super
  assign_meta
end

#height(style = default_style) ⇒ Object


26
27
28
# File 'lib/paperclip-meta/attachment.rb', line 26

def height(style = default_style)
  read_meta style, :height
end

#image_size(style = default_style) ⇒ Object

Return image dimesions (“WxH”) for given style name. If style name not given, return dimesions for default_style.


40
41
42
# File 'lib/paperclip-meta/attachment.rb', line 40

def image_size(style = default_style)
  "#{width(style)}x#{height(style)}"
end

#post_process_styles(*styles) ⇒ Object


16
17
18
19
# File 'lib/paperclip-meta/attachment.rb', line 16

def post_process_styles(*styles)
  super(*styles)
  assign_meta
end

#saveObject


9
10
11
12
13
14
# File 'lib/paperclip-meta/attachment.rb', line 9

def save
  if @queued_for_delete.any? && @queued_for_write.empty?
    instance_write(:meta, meta_encode({}))
  end
  super
end

#size(style = nil) ⇒ Object

Use meta info for style if required


22
23
24
# File 'lib/paperclip-meta/attachment.rb', line 22

def size(style = nil)
  style ? read_meta(style, :size) : super()
end

#width(style = default_style) ⇒ Object


30
31
32
# File 'lib/paperclip-meta/attachment.rb', line 30

def width(style = default_style)
  read_meta style, :width
end