Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 0 additions & 6 deletions config/database.yml.sample

This file was deleted.

3 changes: 3 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
Show.delete_all
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
cbs = Network.create(name: "CBS")
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: "Person of Interest", day_of_week: "Thursday", hour_of_day: 20, network: cbs)
Show.create(name: "Criminal Minds", day_of_week: "Wednesday", hour_of_day: 20, network: cbs)
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 on #{day_of_week}"
end
end
13 changes: 13 additions & 0 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@
puts show
end
end

def find_show
dow = { Monday: 1, Tuesday: 2, Wednesday: 3, Thursday: 4, Friday: 5, Saturday: 6, Sunday: 7 }
puts "Pick a day of week: Use 1 for Monday ... 7 for Sunday"
user_pick = dow.key ( gets.to_i )
Copy link
Member

Choose a reason for hiding this comment

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

Nice use of a hash here! I think that's exactly the way to go. Here you are really retrieving the key from a value (Monday being the key, 1 being the value).

Instead, maybe try:

  days_of_week = {1=>"Monday", 2=>"Tuesday"}
  puts "Pick a day of week: Use 1 for Monday ... 7 for Sunday"
  user_pick = days_of_week.fetch( gets.to_i ) { puts "sorry, not found"}


Network.all.each do |network|
network.shows.each { |show| puts show if show.day_of_week == user_pick.to_s }
end

end

find_show