class Focus::Playlist
Attributes
movies[R]
name[R]
Public Class Methods
new(name)
click to toggle source
# File lib/focus/playlist.rb, line 10 def initialize(name) @name = name.capitalize @movies = [] puts "\n***#{@name}'s Playlist has been created***" end
Public Instance Methods
add_movie(movie)
click to toggle source
# File lib/focus/playlist.rb, line 39 def add_movie(movie) @movies << movie puts "::added #{movie.title}::" end
load_file(from_file)
click to toggle source
# File lib/focus/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
name=(title)
click to toggle source
# File lib/focus/playlist.rb, line 16 def name=(title) @name = title.capitalize puts "Name of playlist has been modified to #{@name}" end
play(viewings)
click to toggle source
# File lib/focus/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()
click to toggle source
# File lib/focus/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")
click to toggle source
# File lib/focus/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()
click to toggle source
# File lib/focus/playlist.rb, line 69 def total_playlist_carbs @movies.reduce(0) {|sum,movie| sum + movie.carbs_consumed} end
total_playlist_snacks()
click to toggle source
# File lib/focus/playlist.rb, line 73 def total_playlist_snacks @movies.reduce(0) {|sum, movie| sum + movie.snack_carbs.keys.size} end