-
Notifications
You must be signed in to change notification settings - Fork 25
Panda, Tiger & Eagle #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
base: master
Are you sure you want to change the base?
Changes from 2 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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Found at: http://www.linuxgazette.net/issue65/padala.html | ||
|
|
||
| # ATTRIBUTES | ||
| RESET = 0 | ||
| BRIGHT = 1 | ||
| DIM = 2 | ||
| UNDERLINE = 3 | ||
| BLINK = 4 | ||
| REVERSE = 7 | ||
| HIDDEN = 8 | ||
|
|
||
| # COLORS | ||
| BLACK = 0 | ||
| RED = 1 | ||
| GREEN = 2 | ||
| YELLOW = 3 | ||
| BLUE = 4 | ||
| MAGENTA = 5 | ||
| CYAN = 6 | ||
| WHITE = 7 | ||
|
|
||
| def text_color(attr, color) | ||
| command = String.new | ||
|
|
||
| # Command is the control command to the terminal | ||
| command << "\e[%d;%dm" % [attr, color + 30] | ||
| printf(command) | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,83 @@ | ||
| require_relative "lib/movie" | ||
| require_relative "lib/api" | ||
| require_relative "lib/text_color" | ||
|
|
||
| def find_movie | ||
| puts "OH HAI. Search?" | ||
| movie_title = gets | ||
| movie = Api.search_by_title(movie_title) | ||
| puts "Found: #{movie.title}. Score: #{movie.score}" | ||
| def movies_average(movies_arr) | ||
| scores = [] | ||
| movies_arr.each { |movie| scores << movie.score } | ||
| scores.inject{ |sum, el| sum + el }.to_f / scores.size | ||
| end | ||
|
|
||
| find_movie | ||
| def movies_slope(movies_arr) | ||
| movies_by_year = movies_arr.sort_by! { |movie| movie.year } | ||
| y2_arr = [] | ||
| y1_arr = [] | ||
| movies_by_year.each do |movie| | ||
| if movie.year == movies_by_year.first.year | ||
| y2_arr << movie | ||
| end | ||
| end | ||
| movies_by_year.each do |movie| | ||
| if movie.year == movies_by_year.last.year | ||
| y1_arr << movie | ||
| end | ||
| end | ||
| y1 = movies_average(y1_arr) | ||
| y2 = movies_average(y2_arr) | ||
| x1 = movies_by_year.last.year | ||
| x2 = movies_by_year.first.year | ||
| (y1 - y2).to_f / (x1 - x2).to_f | ||
| end | ||
|
|
||
| def show_average(movies_arr) | ||
| text_color(BRIGHT, BLUE) | ||
| printf "Average: #{movies_average(movies_arr)}\n" | ||
| text_color(RESET, WHITE) | ||
| end | ||
|
|
||
| def show_contentment(movies_arr) | ||
| if movies_slope(movies_arr) == 0 | ||
| puts "Staying Content" | ||
| elsif movies_slope(movies_arr) > 0 | ||
| text_color(BRIGHT, YELLOW) | ||
| puts "Getting Happier" | ||
| else | ||
| text_color(BRIGHT, MAGENTA) | ||
| puts "Getting Madder" | ||
| end | ||
| text_color(RESET, WHITE) | ||
| end | ||
|
|
||
| def find_movie(movies_arr) | ||
| print "Search: " | ||
| searched_movie = gets.chomp | ||
| movie = Api.search_by_title(searched_movie) | ||
| if movie == :no_movie_found | ||
| text_color(BRIGHT, RED) | ||
| printf "\tCould not find #{searched_movie}\n" | ||
| else | ||
| text_color(BRIGHT, GREEN) | ||
| printf "\tFound: #{movie.title}\n\tScore: #{movie.score}\n" | ||
| movies_arr << movie | ||
| end | ||
| text_color(RESET, WHITE) | ||
| end | ||
|
|
||
| movies_arr = [] | ||
|
|
||
| puts "HI! Welcome to rssll's #{$0}." | ||
|
Member
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. You don't see many |
||
| printf "Search for movies that you really like!\n\n" | ||
|
Member
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. Generally you wouldn't use |
||
| find_movie(movies_arr) | ||
|
|
||
| while true do | ||
| puts "Search Again (Y/N)" | ||
| answer = gets.upcase[0] | ||
| if answer == "Y" | ||
| find_movie | ||
| loop do | ||
| print "Search Again? (Y/N) " | ||
| answer = gets.chomp | ||
| if answer =~ /Y/i | ||
| find_movie(movies_arr) | ||
| if movies_arr.size > 1 | ||
| show_average(movies_arr) | ||
| show_contentment(movies_arr) | ||
| end | ||
| else | ||
| break | ||
| end | ||
|
|
||
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.
I would rather you use map here; though I'm having a bit of trouble reading what you're doing here. I THINK you're trying to get the first year and last year of movies in the movies, right? If so, maybe try sorting them by year and pulling the first and last.