Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ipc103 committed Mar 1, 2017
0 parents commit e5f1cfa
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# A sample Gemfile
source "https://rubygems.org"

# gem "rails"
gem 'pry-byebug'
gem 'require_all'
25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
GEM
remote: https://rubygems.org/
specs:
byebug (8.2.2)
coderay (1.1.1)
method_source (0.8.2)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.3.0)
byebug (~> 8.0)
pry (~> 0.10)
require_all (1.3.3)
slop (3.6.0)

PLATFORMS
ruby

DEPENDENCIES
pry-byebug
require_all

BUNDLED WITH
1.10.6
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Object Relations Assessment

For this assignment, we'll be working with a Yelp-style domain. We have three models - Restaurant, Customer, and Review.
For our purposes, a Restaurant has many reviews, a Customer has many reviews, and Restaurant - Customer is a many to many relationship.

If you are not sketching out your domain, and thinking about single source of truth,
you are doing it wrong :(

## Topics

+ Classes vs Instances
+ Variable Scope ( Class, Instance, Local )
+ Object Relationships
+ Arrays and Array Methods
+ Class Methods

## Instructions

Build the following methods on the customer class
+ Customer.all
+ should return all of the customers
+ Customer.find_by_name(name)
+ given a string of a full name, returns the first customer whose full name matches
+ Customer.find_all_by_first_name(name)
+ given a string of a first name, returns an array containing all customers with that first name
+ Customer#add_review
+ given some content and a restaurant, creates a new review and associates it with that customer and that restaurant

Build out the following methods on the Review class

+ Review.all
+ returns all of the reviews
+ Review#customer
+ returns the customer for that given review
+ Review#restaurant
+ returns the restaurant for that given review

Build out the following methods on the restaurant class

+ Restaurant.all
+ returns an array of all restaurants
+ Restaurant.find_by_name(name)
+ given a string of restaurant name, returns the first restaurant that matches
+ Restaurant#reviews
+ returns an array of all reviews for that restaurant
+ Restaurant#customers
+ should return all of the customers who have written reviews of that restaurant.
18 changes: 18 additions & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Customer
attr_accessor :first_name, :last_name

@@all = []

def self.all
@@all
end

def initialize(name)
@name = name
@@all << self
end

def full_name
"#{first_name} #{last_name}"
end
end
12 changes: 12 additions & 0 deletions app/models/restaurant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Restaurant
attr_accessor :name

@@all = []

def initialize(name)
self.name=(name)
@@all << self
@reviews = []
end

end
4 changes: 4 additions & 0 deletions app/models/review.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Review

end

3 changes: 3 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'bundler/setup'
Bundler.require
require_all 'app'
33 changes: 33 additions & 0 deletions notes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# We want to add the following methods to each of the classes
# An all method, where each object is added upon initialization of the object
# A find_by_name method for both the customer and the restaurant


# If you are not sketching out your domain, and thinking about single source of truth,
# you are doing it wrong :(

# Build the following methods on the customer class
# Customer.all
# should return all of the customers
# Customer.find_by_name(name)
# given a string of a full name, returns the first customer whose full name matches
# Customer.find_all_by_first_name(name)
# # given a string of a first name, returns an array containing all customers with that first name
# Customer#add_review
# given some content and a restaurant, creates a new review and associates it with that customer and that restaurant

# Review.all
# returns all of the reviews
# Review#customer
# returns the customer for that given review
# Review#restaurant
# returns the restaurant for that given review

# Restaurant.all
# returns an array of all restaurants
# Restaurant.find_by_name(name)
# given a string of restaurant name, returns the first restaurant that matches
# Restaurant#reviews
# returns an array of all reviews for that restaurant
# Restaurant#customers
# should return all of the customers who have written reviews of that restaurant.
7 changes: 7 additions & 0 deletions tools/console.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative '../config/environment.rb'

def reload
load 'config/environment.rb'
end

Pry.start

0 comments on commit e5f1cfa

Please sign in to comment.