Skip to content

Instantly share code, notes, and snippets.

@tejo
Created September 30, 2009 13:18
Show Gist options
  • Select an option

  • Save tejo/198078 to your computer and use it in GitHub Desktop.

Select an option

Save tejo/198078 to your computer and use it in GitHub Desktop.
class Deal
include DataMapper::Resource
property :id, Serial
property :name_key, String
property :dealer, String
property :name, Text
property :link, Text
property :price, Integer
property :visible, Boolean, :default => true
property :created_at, DateTime
validates_is_unique :name_key
def name_key=(link)
attribute_set(:name_key, Digest::MD5.hexdigest(link))
end
#TODO optimize this evil loop
def self.to_notify(opts={})
opts = {:keywords => [] }.merge!(opts)
deals = []
opts[:keywords].each do |key|
deals = deals | Deal.all(:visible => true, :name.like => "%#{key}%")
end
deals
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment