Class: Mochee::Playlist
- Inherits:
-
Object
- Object
- Mochee::Playlist
- Defined in:
- lib/mochee/playlist.rb
Instance Attribute Summary collapse
-
#movies ⇒ Object
readonly
Returns the value of attribute movies.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_movie(movie) ⇒ Object
-
#initialize(name) ⇒ Playlist
constructor
A new instance of Playlist.
- #load_file(from_file) ⇒ Object
- #play(viewings) ⇒ Object
- #print_stats ⇒ Object
- #save_file(to_file = "final_records") ⇒ Object
- #total_playlist_carbs ⇒ Object
- #total_playlist_snacks ⇒ Object
Constructor Details
#initialize(name) ⇒ Playlist
Returns a new instance of Playlist.
10 11 12 13 14 |
# File 'lib/mochee/playlist.rb', line 10 def initialize(name) @name = name.capitalize @movies = [] puts "\n***#{@name}'s Playlist has been created***" end |
Instance Attribute Details
#movies ⇒ Object (readonly)
Returns the value of attribute movies.
8 9 10 |
# File 'lib/mochee/playlist.rb', line 8 def movies @movies end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/mochee/playlist.rb', line 8 def name @name end |
Instance Method Details
#add_movie(movie) ⇒ Object
39 40 41 42 |
# File 'lib/mochee/playlist.rb', line 39 def add_movie(movie) @movies << movie puts "::added #{movie.title}::" end |
#load_file(from_file) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/mochee/playlist.rb', line 21 def load_file(from_file) puts "\n::::Loding File #{from_file.capitalize}::::" File.readlines(from_file).each do |line| add_movie(Movie.convert(line)) end end |
#play(viewings) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mochee/playlist.rb', line 44 def play(viewings) puts "\n\n~~Playing #{@name}'s playlist:~~" @movies.sort {|x,y| y.rank <=> x.rank}.each do |movie| puts "\tTrack: #{movie}" end snacks = SnackBar::SNACKS puts "\nThere are #{snacks.size} snacks available in the Snack Bar." snacks.sort {|x,y| y.carbs <=> x.carbs }.map.with_index(1) {|snack,i| puts "\t#{i}. #{snack.name.capitalize} - #{snack.carbs} carbs"} puts "\nStarting the Movie,Enjoy your show!!" 1.upto(viewings) do |counter| puts "\nViewing: #{counter}" @movies.sort.each do |movie| Dok2AndQuiet.review(movie) snack = SnackBar.random movie.ate_snack(snack) puts movie puts "**************************************************" end end end |
#print_stats ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mochee/playlist.rb', line 78 def print_stats puts "\n\n\nPlayList #{@name.upcase!}'s Stats: #{total_playlist_carbs} carbs - #{total_playlist_snacks} snacks" @movies.sort {|x,y| y.carbs_consumed <=> x.carbs_consumed }.map.with_index(1) do |movie,i| puts "#{i}. #{movie.title} - #{movie.carbs_consumed} *total* grand carbs" movie.expose_hash {|key| puts "\t #{key.name} - #{key.carbs} carbs"} end hits, flops = @movies.partition {|m| m.hit? } puts "\nHits: " hits.sort.each do |movie| puts "\t#{movie}" end puts "\nFlops: " flops.sort.each do |movie| puts "\t#{movie}" end end |
#save_file(to_file = "final_records") ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mochee/playlist.rb', line 28 def save_file(to_file="final_records") puts "\n::::::Saving To File #{to_file.capitalize}::::::" File.open(to_file,"a+") do |file| @movies.sort.map.with_index(1) do |movie, i| file.puts("\t#{i}.#{movie.title},#{movie.rank}") end time = Time.new file.puts time.strftime("Printed on %m/%d/%Y at %I:%M%p") end end |
#total_playlist_carbs ⇒ Object
69 70 71 |
# File 'lib/mochee/playlist.rb', line 69 def total_playlist_carbs @movies.reduce(0) {|sum,movie| sum + movie.carbs_consumed} end |
#total_playlist_snacks ⇒ Object
73 74 75 |
# File 'lib/mochee/playlist.rb', line 73 def total_playlist_snacks @movies.reduce(0) {|sum, movie| sum + movie.snack_carbs.keys.size} end |