Skip to content

Instantly share code, notes, and snippets.

@graybill
Created May 4, 2011 21:08
Show Gist options
  • Save graybill/956037 to your computer and use it in GitHub Desktop.
Save graybill/956037 to your computer and use it in GitHub Desktop.
class Location
include MongoMapper::Document
scope :restaurants, where(:loc_type => 'restaurant')
scope :bars, where(:loc_type => 'bar')
scope :trucks, where(:loc_type => 'truck')
key :name, String, :required => true
key :store_no, Integer
key :address1, String
key :address2, String
key :city, String
key :state, String
key :zipcode, Integer
key :phone_no, String
key :description, String
key :inventory, Integer
key :loc_type, String
key :loc, Array
key :hours, Array
key :debug, Array
def self.coordinates(addr)
include Geokit::Geocoders
res=MultiGeocoder.geocode(addr)
r = res.ll.split(',')
[r[0].to_f, r[1].to_f]
end
def self.create(params = nil)
self.loc = coordinates(params[:address1] + "+PA+" + params[:zipcode])
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment