Last active
December 25, 2015 00:09
-
-
Save manleyhimself/6886032 to your computer and use it in GitHub Desktop.
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
| class Jukebox | |
| attr_accessor :songs | |
| DefaultSongs = [ | |
| "The Phoenix - 1901", | |
| "Tokyo Police Club - Wait Up", | |
| "Sufjan Stevens - Too Much", | |
| "The Naked and the Famous - Young Blood", | |
| "(Far From) Home - Tiga", | |
| "The Cults - Abducted", | |
| "The Phoenix - Consolation Prizes" | |
| ] | |
| def initialize(songs = DefaultSongs) | |
| @songs = songs | |
| @run = true | |
| end | |
| def call | |
| puts "\nHey, you're interacting with a cyber jukebox!" | |
| while @run == true | |
| playing | |
| end | |
| end | |
| def playing | |
| puts "\nHere are your option: 'help', 'play', 'list', 'exit'" | |
| input = gets.chomp.downcase | |
| if input == "help" | |
| help | |
| elsif input == "list" | |
| list | |
| elsif input == "play" | |
| play | |
| elsif input == "exit" | |
| @run = false | |
| else | |
| puts "\nYou didn't provide a proper command" | |
| end | |
| end | |
| def play | |
| while true | |
| list | |
| puts "\nWhich song would you like to play? (type: 'exit' to return to other features)\n" | |
| song_choice = gets.chomp.to_i | |
| if song_choice == 0 | |
| break | |
| elsif song_choice <= songs.length | |
| puts "\nPlaying: #{songs[song_choice - 1]}\n" | |
| else | |
| puts "\nNot a valid option.\n" | |
| end | |
| #(song_choice >= 1 && song_choice <= @songs.length) ? puts("\nPlaying: #{@songs[song_choice - 1]}\n") : break | |
| end | |
| end | |
| def help | |
| puts "\nhelp is on the way!" | |
| end | |
| def list | |
| songs.each_with_index { |song, index| puts "\n #{index+1}: #{song} \n"} | |
| end | |
| end | |
| songs = [ "Tokyo Police Club - Wait Up", | |
| "Sufjan Stevens - Too Much", | |
| "The Naked and the Famous - Young Blood"] | |
| j = Jukebox.new(songs) | |
| j.call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment