From 817ad8e3c25f7997f4e4bf46751d729cb49066ed Mon Sep 17 00:00:00 2001 From: mexicanrb Date: Thu, 25 Jul 2013 01:01:49 -0500 Subject: [PATCH 1/2] Episode 3 --- db/seed.rb | 4 ++++ models/show.rb | 2 +- watchman.rb | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..1593757 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 Gui", 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..1e6b897 100644 --- a/watchman.rb +++ b/watchman.rb @@ -13,3 +13,9 @@ puts show end end + +puts +puts "The TV shows are:" +Show.all.each do | show | + puts show +end \ No newline at end of file From 2069d82bed46251910ecceea085ac5176a9984dc Mon Sep 17 00:00:00 2001 From: mexicanrb Date: Thu, 25 Jul 2013 01:32:19 -0500 Subject: [PATCH 2/2] Eagle level --- db/seed.rb | 2 +- watchman.rb | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/db/seed.rb b/db/seed.rb index 1593757..1b50a67 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -8,4 +8,4 @@ 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 Gui", day_of_week: "Monday", hour_of_day: 01, network: fox) \ No newline at end of file +Show.create(name: "Family Guy", day_of_week: "Monday", hour_of_day: 01, network: fox) \ No newline at end of file diff --git a/watchman.rb b/watchman.rb index 1e6b897..e7b9862 100644 --- a/watchman.rb +++ b/watchman.rb @@ -7,15 +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 -puts -puts "The TV shows are:" -Show.all.each do | show | - puts show -end \ No newline at end of file +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