Class: Clipping

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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



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

def self.find_recent(options = {:limit => 5})
  where("created_at > '#{7.days.ago.iso8601}'").order("created_at DESC").limit(options[:limit])
end


22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/clipping.rb', line 22

def self.find_related_to(clipping, options = {})
  options.reverse_merge!({:limit => 8,
      :order => 'clippings.created_at DESC',
      :conditions => [ 'clippings.id != ?', clipping.id ]
  })

  limit(options[:limit]).
    order(options[:order]).
    where(options[:conditions]).
    tagged_with(clipping.tags.collect{|t| t.name }, :any => true)
end

Instance Method Details

#add_imageObject



62
63
64
65
66
67
68
69
70
71
# File 'app/models/clipping.rb', line 62

def add_image
  begin
    clipping_image = ClippingImage.new
    uploaded_data = clipping_image.data_from_url(self.image_url)
    clipping_image.asset = uploaded_data
    self.image = clipping_image
  rescue
    nil
  end
end

#has_been_favorited_by(user = nil, remote_ip = nil) ⇒ Object



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

def has_been_favorited_by(user = nil, remote_ip = nil)
  f = Favorite.find_by_user_or_ip_address(self, user, remote_ip)
  return f
end

#image_uri(size = '') ⇒ Object



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

def image_uri(size = '')
  image && image.asset.url(size) || image_url
end

#next_clippingObject



41
42
43
# File 'app/models/clipping.rb', line 41

def next_clipping
  self.user.clippings.where('created_at > ?', self.created_at).order('created_at ASC').first
end

#ownerObject



45
46
47
# File 'app/models/clipping.rb', line 45

def owner
  self.user
end

#previous_clippingObject



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

def previous_clipping
  self.user.clippings.order('created_at DESC').where('created_at < ?', self.created_at).first
end

#save_imageObject



73
74
75
76
77
78
# File 'app/models/clipping.rb', line 73

def save_image
  if valid? && image
    image.attachable = self
    image.save
  end
end

#title_for_rssObject



53
54
55
# File 'app/models/clipping.rb', line 53

def title_for_rss
  description.empty? ? created_at.to_formatted_s(:long) : description
end