-
Notifications
You must be signed in to change notification settings - Fork 27
Week 3 pull request - Panda and Tiger Levels #13
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
Open
moserrya
wants to merge
1
commit into
RubyoffRails:master
Choose a base branch
from
moserrya:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
require 'date' | ||
|
||
require "./db/setup" | ||
Dir.glob('./models/*').each { |r| require r} | ||
require "./db/seed" | ||
|
||
puts "There are #{Show.count} in the database" | ||
|
||
def ask_user_for_valid_day_of_week | ||
user_date = gets.chomp.capitalize | ||
days_of_the_week = Date::DAYNAMES | ||
count = 0 | ||
max_number_of_tries = 2 | ||
while days_of_the_week.index(user_date).nil? && count < max_number_of_tries | ||
puts "That is not a valid day of the week. Please try again." | ||
user_date = gets.chomp.capitalize | ||
count += 1 | ||
end | ||
if count == max_number_of_tries | ||
user_date = days_of_the_week[Time.new.wday] | ||
puts "No valid date entered, giving shows for today (#{user_date})" | ||
end | ||
user_date | ||
end | ||
|
||
puts "What day of the week do you want to watch shows?" | ||
day_of_interest = ask_user_for_valid_day_of_week | ||
|
||
Network.all.each do |network| | ||
puts "Shows airing on #{network}" | ||
network.shows.each do |show| | ||
puts show | ||
puts show if show.day_of_week == day_of_interest | ||
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. Rather than doing an if statement inside of a loop, I recommend you get an array of items that are valid first, and then loop over those items to puts show. Something like:
Which could be combined if you don't need to access the valid_shows anymore:
|
||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You could probably pull this out into two different methods... maybe something like:
Then you'd use it in subjectively cleaner way: