Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panda, Tiger & Eagle levels complete #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions db/migrate/201212102100_create_sports.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateSports < ActiveRecord::Migration
def change
create_table :sports do |t|
t.string :name
t.string :description
t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# Cleaning Out
Network.delete_all
Show.delete_all
Sport.delete_all
# Create Networks
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
# Create Shows
Show.create(name: "Mad Men", day_of_week: "Sunday", hour_of_day: 22, network: amc)
Show.create(name: "Community", day_of_week: "Thursday", hour_of_day: 20, network: nbc)
Show.create(name: "How I met your mother", day_of_week: "Wednesday", hour_of_day: 20, network: nbc)
Show.create(name: "Modern Family", day_of_week: "Monday", hour_of_day: 19, network: nbc)
# Create Sports
Sport.create(name: "Rugby", description: "Rugby is a style of football named after Rugby School in the United Kingdom. It is seen most prominently in two current sports, rugby league and rugby union.")
Sport.create(name: "Tennis", description: "Tennis is a sport usually played between two players using a racquet and ball. The object of the game is to play the ball in such a way that the opponent is not able to hit a good return.")
Sport.create(name: "Golf", description: "Golf is a precision sport, in which competing players use many types of clubs to hit balls into a series of holes using the fewest number of strokes.")
Sport.create(name: "Boxing", description: "Boxing is a combat sport in which two people engage in a contest of strength, reflexes and endurance by throwing punches at an opponent with gloved hands.")
Sport.create(name: "Soccer", description: "Soccer is a sport played between two teams of eleven players with a spherical ball.")

2 changes: 1 addition & 1 deletion models/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class Show < ActiveRecord::Base
validates_presence_of :name

def to_s
"#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} "
"#{name} airs at #{hour_of_day}:00, #{day_of_week} on #{network} "
end
end
6 changes: 6 additions & 0 deletions models/sport.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Sport < ActiveRecord::Base

def to_s
"#{name}"
end
end
42 changes: 37 additions & 5 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,43 @@
Dir.glob('./models/*').each { |r| require r}
require "./db/seed"

puts "There are #{Show.count} in the database"
puts "There are #{Show.count} shows in the database"
puts
puts "What day would you like to watch shows?"
puts
print '~>'
day = gets.chomp.capitalize

Network.all.each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
puts show
end
network.shows.where(day_of_week: day).each do |show|
puts show
end
end

puts
puts "Great, now I also have some sports I can tell you about."
puts "Check out all the sports I know:"
Sport.all.each do |sport|
puts sport
end
puts "Now choose one and enter it below to find out more about it."
print "~>"

input = gets.chomp.capitalize
sport = Sport.where(name: input).first

while sport.nil?
puts "Sorry, I can't do that right now."
puts "Try another sport..."
print "~>"
input = gets.chomp.capitalize
sport = Sport.where(name: input).first
end

puts
puts "A not so fun fact about #{sport.name}:"
puts

Sport.where(name: input).each do |sport|
puts sport.description
end