Class: PageFile

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Dis::Model
Defined in:
app/models/page_file.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.formatsObject


20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/page_file.rb', line 20

def formats
  {
    "audio/mpeg"      => :mp3,
    "image/gif"       => :gif,
    "image/jpeg"      => :jpg,
    "image/jpg"       => :jpg,
    "image/pjpeg"     => :jpg,
    "image/png"       => :png,
    "application/pdf" => :pdf
  }
end

Instance Method Details

#filename_extensionObject


41
42
43
44
45
46
47
# File 'app/models/page_file.rb', line 41

def filename_extension
  if filename_extension?
    filename.match(/\.([^\.]+)$/)[1]
  else
    ""
  end
end

#filename_extension?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'app/models/page_file.rb', line 49

def filename_extension?
  filename =~ /\./
end

#formatObject


37
38
39
# File 'app/models/page_file.rb', line 37

def format
  self.class.formats[content_type]
end

#format?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'app/models/page_file.rb', line 33

def format?
  content_type && self.class.formats.key?(content_type)
end

#to_paramObject


53
54
55
56
57
58
59
# File 'app/models/page_file.rb', line 53

def to_param
  if filename_extension?
    "#{id}-#{content_hash}.#{filename_extension}"
  else
    "#{id}-#{content_hash}"
  end
end