Created
October 8, 2013 14:38
-
-
Save samueldowens/6885748 to your computer and use it in GitHub Desktop.
jukebox_oo.rb
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
| songs = [ | |
| "1. The Phoenix - 1901", | |
| "2. Tokyo Police Club - Wait Up", | |
| "3. Sufjan Stevens - Too Much", | |
| "4. The Naked and the Famous - Young Blood", | |
| "5. (Far From) Home - Tiga", | |
| "6. The Cults - Abducted", | |
| "7. The Phoenix - Consolation Prizes" | |
| ] | |
| class Jukebox | |
| attr_accessor :songs, :run, :name | |
| def initialize(array) | |
| @run = "yes" | |
| @songs = array | |
| greeting | |
| start | |
| end | |
| def greeting | |
| puts "Hello and welcome to the jukebox." | |
| puts "Please let me know your name..." | |
| @name = gets.chomp | |
| puts "" | |
| puts "Okay #{@name.capitalize}, let me tell you how this works." | |
| puts "" | |
| puts "You can type any of the following commands..." | |
| puts "" | |
| puts "----------------------------------------------------------------------" | |
| puts "'Help' in case you forget how the program works, this will remind you." | |
| puts "'Play' where you will be able to play a song." | |
| puts "'List' this will show you the list of available songs." | |
| puts "'Exit' to exit the program." | |
| puts "----------------------------------------------------------------------" | |
| end | |
| def help | |
| puts "" | |
| puts "----------------------------------------------------------------------" | |
| puts "You can type any of the following commands..." | |
| puts "'Help' in case you forget how the program works, this will remind you." | |
| puts "'Play' where you will be able to play a song." | |
| puts "'List' this will show you the list of available songs." | |
| puts "'Exit' to exit the program." | |
| puts "----------------------------------------------------------------------" | |
| puts "" | |
| end | |
| def play | |
| puts "" | |
| puts "------------------------------------------" | |
| puts @songs | |
| puts "------------------------------------------" | |
| puts "" | |
| puts "Please type the song name or number you want me to play." | |
| track = gets.downcase.chomp | |
| case track | |
| when "1901", "1" | |
| puts "" | |
| puts "***** Playing 1901 by The Phoenix. *****" | |
| puts "" | |
| puts "Wasn't that a great tune? We're not just juking you around!" | |
| puts "" | |
| when "wait up", "2" | |
| puts "" | |
| puts "***** Playing Wait Up by Tokyo Police Club. *****" | |
| puts "" | |
| puts "Wow, your taste in music is a total juke." | |
| puts "" | |
| when "too much", "3" | |
| puts "" | |
| puts "***** Playing Too Much by Sufjan Stevens *****" | |
| puts "" | |
| puts "Are you tired of my jukes yet?" | |
| puts "" | |
| when "young blood", "4" | |
| puts "" | |
| puts "***** Playing Young Blood by The Naked and Famous *****" | |
| puts "" | |
| puts "Milk was a bad choice!" | |
| puts "" | |
| when "tiga", "5" | |
| puts "" | |
| puts "***** Playing Tiga by (Far From) Home *****" | |
| puts "" | |
| puts "Yawn, I hope you didn't pay to hear that." | |
| puts "" | |
| when "abducted", "6" | |
| puts "" | |
| puts "***** Playing Abducted by The Cults *****" | |
| puts "" | |
| puts "I'm fresh out of good jukes, so I'm going to use the same old pun." | |
| puts "" | |
| when "consolation prizes", "7" | |
| puts "" | |
| puts "***** Playing Consolation Prizes by The Phoenix *****" | |
| puts "" | |
| puts "Another Phoenix song? I need some more variety!" | |
| puts "" | |
| else | |
| puts "" | |
| puts "That was an invalid input, try again." | |
| puts "" | |
| end | |
| end | |
| def list | |
| puts "" | |
| puts "Here are the lists of songs and artists contained in the jukebox..." | |
| puts "" | |
| puts "------------------------------------------" | |
| puts @songs | |
| puts "------------------------------------------" | |
| puts "" | |
| end | |
| def exit | |
| @run = "no" | |
| puts "" | |
| puts "Thanks for using the Jukebox!" | |
| end | |
| def command | |
| puts "What would you like to do? " | |
| command = gets.downcase.chomp | |
| case command | |
| when "help" | |
| help | |
| when "play" | |
| play | |
| when "list" | |
| list | |
| when "exit" | |
| exit | |
| else | |
| puts "That was an invalid command" | |
| end | |
| end | |
| end | |
| def start | |
| while @run == "yes" do | |
| command | |
| end | |
| end | |
| j = Jukebox.new(songs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment