Class: AmpleAssets::File

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ample_assets/file.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/ample_assets/file.rb', line 66

def as_json(options={})
  search_terms = keywords.split(" ") rescue nil
  { :id => id,
    :uid => attachment_uid,
    :filename => attachment_name,
    :document => is_doc? ? 'true' : 'false',
    :orientation => orientation,
    :mime_type => attachment_mime_type,
    :keywords => search_terms,
    :url => attachment.url,
    :gravity => attachment_gravity,
    :size => "#{attachment.width}x#{attachment.height}",
    :sizes => { :tn => thumbnail, :md => medium }
  }
end

#is_doc?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/ample_assets/file.rb', line 42

def is_doc?
  AmpleAssets.allowed_mime_types[:documents].include?(attachment_mime_type)
end

#is_image?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/ample_assets/file.rb', line 38

def is_image?
  AmpleAssets.allowed_mime_types[:images].include?(attachment_mime_type)
end

#is_pdf?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/ample_assets/file.rb', line 34

def is_pdf?
  attachment_mime_type == 'application/pdf'
end

#is_swf?Boolean

—————————————————- Instance Methods

Returns:

  • (Boolean)


30
31
32
# File 'app/models/ample_assets/file.rb', line 30

def is_swf?
  attachment_mime_type == 'application/x-shockwave-flash'
end

#mediumObject



58
59
60
# File 'app/models/ample_assets/file.rb', line 58

def medium
  attachment.thumb('500x>').url if is_image?
end

#orientationObject



62
63
64
# File 'app/models/ample_assets/file.rb', line 62

def orientation
  attachment.portrait? ? 'portrait' : 'landscape'
end

#thumbnailObject



46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/ample_assets/file.rb', line 46

def thumbnail
  if is_image?
    attachment.process(:matte, :dimensions => '75x75', :background => 'white').url
  elsif is_swf?
    AmpleAssets.icons[self.attachment_mime_type]
  elsif AmpleAssets.icons.has_key?(self.attachment_mime_type)
    AmpleAssets.icons[self.attachment_mime_type]
  else
    AmpleAssets.icons[:other]
  end
end