class Unicafe::Restaurant
Constants
- LIST_OF_RESTAURANTS
Public Class Methods
distances(latitude, longitude)
click to toggle source
# File lib/unicafe/restaurant.rb, line 70 def self.distances(latitude, longitude) distances = {} LIST_OF_RESTAURANTS.each do |key, hash| restaurant = self.find_by_id(key) distances[restaurant.distance(latitude, longitude)] = restaurant end distances end
find_by_id(id)
click to toggle source
# File lib/unicafe/restaurant.rb, line 53 def self.find_by_id id self.new id end
find_by_name(name)
click to toggle source
# File lib/unicafe/restaurant.rb, line 57 def self.find_by_name name self.find_by_id self.name_to_id(name) end
name_to_id(name)
click to toggle source
# File lib/unicafe/restaurant.rb, line 61 def self.name_to_id name LIST_OF_RESTAURANTS.select{|key, hash| hash[:name] == name}.map{|key, hash| key}.first || raise(NotFound) end
nearest(latitude, longitude)
click to toggle source
# File lib/unicafe/restaurant.rb, line 65 def self.nearest(latitude, longitude) distances_with_restaurants = self.distances(latitude, longitude) distances_with_restaurants[distances_with_restaurants.keys.min] end
new(id)
click to toggle source
# File lib/unicafe/restaurant.rb, line 27 def initialize id @id = id end
Public Instance Methods
distance(latitude, longitude)
click to toggle source
# File lib/unicafe/restaurant.rb, line 47 def distance(latitude, longitude) Geocoder::Calculations.distance_between([self.latitude, self.longitude], [latitude, longitude], :units => :km) end
latitude()
click to toggle source
# File lib/unicafe/restaurant.rb, line 35 def latitude @latitude ||= LIST_OF_RESTAURANTS[@id][:latitude] end
longitude()
click to toggle source
# File lib/unicafe/restaurant.rb, line 39 def longitude @longitude ||= LIST_OF_RESTAURANTS[@id][:longitude] end
lunches()
click to toggle source
# File lib/unicafe/restaurant.rb, line 43 def lunches ::Unicafe::Lunch.lunches_for_restaurant(@id) end
name()
click to toggle source
# File lib/unicafe/restaurant.rb, line 31 def name @name ||= LIST_OF_RESTAURANTS[@id][:name] end