Class: PapermillAsset

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/papermill/papermill_asset.rb

Instance Method Summary collapse

Instance Method Details

#content_typeObject



49
50
51
# File 'lib/papermill/papermill_asset.rb', line 49

def content_type
  file_content_type && file_content_type.split("/")
end

#destroy_filesObject



57
58
59
60
# File 'lib/papermill/papermill_asset.rb', line 57

def destroy_files
  system "rm -rf #{Papermill::papermill_interpolated_path({":id_partition" => self.id_partition}, ':id_partition')}/"
  true
end

#heightObject



37
38
39
# File 'lib/papermill/papermill_asset.rb', line 37

def height
  image? && Paperclip::Geometry.from_file(file).height
end

#id_partitionObject



25
26
27
# File 'lib/papermill/papermill_asset.rb', line 25

def id_partition
  ("%09d" % self.id).scan(/\d{3}/).join("/")
end

#image?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/papermill/papermill_asset.rb', line 53

def image?
  content_type && content_type.first == "image" && content_type[1]
end

#nameObject



29
30
31
# File 'lib/papermill/papermill_asset.rb', line 29

def name
  file_file_name
end

#sizeObject



41
42
43
# File 'lib/papermill/papermill_asset.rb', line 41

def size
  file_file_size
end

#swfupload_file=(data) ⇒ Object



20
21
22
23
# File 'lib/papermill/papermill_asset.rb', line 20

def swfupload_file=(data)
  data.content_type = MIME::Types.type_for(data.original_filename).to_s
  self.file = data
end

#url(style = nil) ⇒ Object



45
46
47
# File 'lib/papermill/papermill_asset.rb', line 45

def url(style = nil)
  file.url(style && CGI::escape(style.to_s))
end

#widthObject



33
34
35
# File 'lib/papermill/papermill_asset.rb', line 33

def width
  image? && Paperclip::Geometry.from_file(file).width
end