Class: Photo

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
UrlUpload
Defined in:
app/models/photo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UrlUpload

#data_from_url, #validate

Instance Attribute Details

#crop_hObject

Returns the value of attribute crop_h


12
13
14
# File 'app/models/photo.rb', line 12

def crop_h
  @crop_h
end

#crop_wObject

Returns the value of attribute crop_w


12
13
14
# File 'app/models/photo.rb', line 12

def crop_w
  @crop_w
end

#crop_xObject

Returns the value of attribute crop_x


12
13
14
# File 'app/models/photo.rb', line 12

def crop_x
  @crop_x
end

#crop_yObject

Returns the value of attribute crop_y


12
13
14
# File 'app/models/photo.rb', line 12

def crop_y
  @crop_y
end

#photo_remote_urlObject

Returns the value of attribute photo_remote_url


12
13
14
# File 'app/models/photo.rb', line 12

def photo_remote_url
  @photo_remote_url
end

Class Method Details

.find_recent(options = {:limit => 3}) ⇒ Object


57
58
59
# File 'app/models/photo.rb', line 57

def self.find_recent(options = {:limit => 3})
  self.new_this_week.limit(options[:limit])
end

61
62
63
64
65
66
67
# File 'app/models/photo.rb', line 61

def self.find_related_to(photo, options = {})
  options.reverse_merge!({:limit => 8,
      :order => 'created_at DESC',
      :conditions => ['photos.id != ?', photo.id]
  })
  limit(options[:limit]).order(options[:order]).where(options[:conditions]).tagged_with(photo.tags.collect{|t| t.name }, :any => true)
end

Instance Method Details

#cropping?Boolean

Returns:

  • (Boolean)

69
70
71
# File 'app/models/photo.rb', line 69

def cropping?
  !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end

#description_for_rssObject


32
33
34
# File 'app/models/photo.rb', line 32

def description_for_rss
  "<a href='#{self.link_for_rss}' title='#{self.name}'><img src='#{self.photo.url(:large)}' alt='#{self.name}' /><br />#{self.description}</a>"
end

#display_nameObject


28
29
30
# File 'app/models/photo.rb', line 28

def display_name
  (self.name && self.name.length>0) ? self.name : "#{:created_at.l.downcase}: #{I18n.l(self.created_at, :format => :published_date)}"
end

#next_in_albumObject


51
52
53
54
# File 'app/models/photo.rb', line 51

def next_in_album
  return nil unless self.album
  self.user.photos.where('created_at > ? and album_id = ?', created_at, self.album_id).last
end

#next_photoObject


43
44
45
# File 'app/models/photo.rb', line 43

def next_photo
  self.user.photos.where('created_at > ?', created_at).last
end

#ownerObject


36
37
38
# File 'app/models/photo.rb', line 36

def owner
  self.user
end

#photo_geometry(style = :original) ⇒ Object


73
74
75
76
# File 'app/models/photo.rb', line 73

def photo_geometry(style = :original)
  @geometry ||= {}
  @geometry[style] ||= Paperclip::Geometry.from_file(photo.path(style))
end

#previous_in_albumObject


47
48
49
50
# File 'app/models/photo.rb', line 47

def previous_in_album
  return nil unless self.album
  self.user.photos.where('created_at < ? and album_id = ?', created_at, self.album.id).first
end

#previous_photoObject


40
41
42
# File 'app/models/photo.rb', line 40

def previous_photo
  self.user.photos.where('created_at < ?', created_at).first
end