-
Notifications
You must be signed in to change notification settings - Fork 27
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
Tiger Level #19
base: master
Are you sure you want to change the base?
Tiger Level #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,35 @@ | |
puts show | ||
end | ||
end | ||
|
||
def search_again | ||
while true do | ||
puts "Search Again (Y/N)" | ||
answer = gets.upcase[0] | ||
if answer == "Y" | ||
find_show | ||
else | ||
break | ||
end | ||
end | ||
end | ||
|
||
|
||
def find_show | ||
puts "What day do you want to watch TV?" | ||
day = gets.chomp | ||
|
||
shows = Show.find(:all, :conditions => {:day_of_week => day}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is Rails 2.x style finders --- where you call "find" and give it a list of conditions. While this will work, it's pretty old school at this point. What you want to use are "scopes". shows = Show.where(:day_of_week => day) The cool thing about scopes is you can chain them: shows = Show.where(:day_of_week => day).where(:network => "AMC") By default, this will return all results, but you can add a ".first" to it to return the first result. |
||
|
||
unless shows.empty? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have many rules on Ruby, but one is "no unless/else". I would rather see this as: if shows.any?
# loop throughs shows
else
puts "nada"
end |
||
shows.each do |show| | ||
puts show | ||
end | ||
else | ||
puts "There was nothing found for #{day}" | ||
end | ||
search_again | ||
end | ||
|
||
find_show | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you use the "inspect" method on id ---- each object has both a to_s and an inspect method, but for different uses. Inspect should only be used for IRB style introspection. Basically looking at an object. Here you could just do:
"#{id}: #{name} airs at #{day_of_week}:#{hour_of_day}:00 on #{network} "