Last active
October 22, 2016 02:02
-
-
Save lizdenhup/5276a569d234354a222239895940d243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AirBnbMod | |
module InstanceMethods | |
end | |
module ClassMethods | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class City < ActiveRecord::Base | |
include AirBnbMod | |
has_many :neighborhoods | |
has_many :listings, :through => :neighborhoods | |
has_many :reservations, :through => :listings | |
def city_openings(start_date, end_date) | |
available_reservations = [] | |
listings.each do |listing| | |
available = listing.reservations.all? do |res| | |
Date.parse(start_date) >= res.checkout || Date.parse(end_date) <= res.checkin | |
end | |
if available | |
available_reservations << listing | |
end | |
end | |
available_reservations | |
end | |
def self.highest_ratio_res_to_listings | |
City.all.max_by do |city| | |
res = city.reservations.count | |
city_listings = city.listings.count | |
res.to_f/city_listings | |
end | |
end | |
def self.most_res | |
City.all.max_by do |city| | |
city.reservations.count | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Neighborhood < ActiveRecord::Base | |
include AirBnbMod | |
belongs_to :city | |
has_many :listings | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment