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

Episode 3 #22

Open
wants to merge 2 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
4 changes: 4 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
Show.delete_all
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
fox = Network.create(name: "FOX")

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: "The Walking Dead", day_of_week: "Saturday", hour_of_day: 23, network: fox)
Show.create(name: "Family Guy", day_of_week: "Monday", hour_of_day: 01, network: fox)
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
30 changes: 25 additions & 5 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,29 @@

puts "There are #{Show.count} in the database"

Network.all.each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
puts show
end
def get_shows
puts "Enter a day of the week to see the shows:"
day = gets.chomp.downcase.capitalize
unless Show.where(day_of_week: day).empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a hard rule about unless/else ---- I wouldn't let it past a code review. ... It's hard to keep it in your brain; instead, keep to if/else.

unless with no else is fine.

Show.where(day_of_week: day).each { |s| puts s }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the Show query would execute twice here -- probably want to:

shows = Show.where(day_of_week: day)
shows.each { |s| puts s }
puts "There are no shows for #{day}" if shows.blank?

or the somewhat cooler:

Show.where(day_of_week: day).tap do |shows|
  shows.each { |s| puts s }
  puts "There are no shows for #{day}" if shows.blank?
end

else
puts "There are no shows for #{day}"
end
continue
end

def continue
puts "Do you want to continue searching? (Y/N)"
answer = gets.chomp.upcase
if answer == 'Y'
get_shows
elsif answer == 'N'
exit
else
puts "Unknown answer..."
continue
end
end


get_shows