Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
nbc = Network.create(name: "NBC")
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: "Monday Show", day_of_week: "Monday", hour_of_day: 20, network: amc)
Show.create(name: "Sunday Show", day_of_week: "Sunday", hour_of_day: 20, network: nbc)
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 #{day_of_week} #{hour_of_day}:00 on #{network} "
end
end
48 changes: 41 additions & 7 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,48 @@
require 'bundler/setup'

require "./db/setup"
Dir.glob('./models/*').each { |r| require r}
Dir.glob('./models/*').each { |r| require r }
require "./db/seed"

puts "There are #{Show.count} in the database"
WEEK_DAY = {
'1' => "Monday",
'2' => "Tuesday",
'3' => "Wednesday",
'4' => "Thursday",
'5' => "Friday",
'6' => "Saturday",
'7' => "Sunday"
}

def select_day
puts "-" * 80
puts "Which week day do you want watch TV shows?"
puts "1: Monday, 2: Tuesday, 3: Wednesday, 4: Thursday, 5: Friday, 6: Saturday, 7: Sunday or Q: Quit"
STDOUT.write "Select a day [1~7 or Q]:"
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably recommend to either stick with puts or STDOUT.

gets.chomp
end

while true
day = select_day

if day.upcase == 'Q'
puts "Goodbye!"
break
end

unless day.match(/^[1-7]$/)
Copy link
Member

Choose a reason for hiding this comment

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

Good use of regexes. For somethings like this, I might forgo that and do something a little easier to read. (regex's are usually complex [mostly]).

unless (1..7).include?(day)

puts "No such day: '#{day}', please select again!"
next
end

sday = WEEK_DAY[day]
Copy link
Member

Choose a reason for hiding this comment

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

sday probably stands for selected day, right? Convention in ruby is to go ahead and use selected_day

Copy link
Author

Choose a reason for hiding this comment

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

You are right 😄
I need to get rid of this bad habit!

shows = Show.where(day_of_week: sday)

if shows.empty?
puts "No shows on #{sday}"
else
puts "Shows on #{sday}:"
shows.each {|show| puts show}
end

Network.all.each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
puts show
end
end