diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..1b50a67 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -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) \ No newline at end of file diff --git a/models/show.rb b/models/show.rb index 6c82f65..8987a44 100644 --- a/models/show.rb +++ b/models/show.rb @@ -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 diff --git a/watchman.rb b/watchman.rb index ebe9be4..e7b9862 100644 --- a/watchman.rb +++ b/watchman.rb @@ -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? + Show.where(day_of_week: day).each { |s| puts s } + 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 \ No newline at end of file