Last active
December 25, 2015 00:18
-
-
Save gregeng/6886227 to your computer and use it in GitHub Desktop.
oop-jukebox-practice
This file contains 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
# Build a Jukebox | |
require 'pry' | |
songs = [ | |
"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", | |
"Miley Cyrus - We Can't Stop" | |
] | |
class Jukebox | |
@@songs = [] | |
def initialize(songs) | |
songs.each { |x| @@songs << x } | |
end | |
def call | |
loop do | |
puts "Please enter a command:" | |
command = input | |
case command | |
when "play" | |
puts "What song would you like to play? By # please." | |
list | |
play | |
puts | |
when "exit" | |
puts "Goodbye!" | |
break | |
when "list" | |
list | |
puts | |
when "help" | |
puts "I support help, play, exit and list" | |
puts | |
else | |
puts "What are you talking about?" | |
puts | |
end | |
end | |
end | |
def list | |
@@songs.each_with_index do |song, i| | |
puts "#{i+1}. #{song}" | |
end | |
end | |
def input | |
gets.downcase.strip | |
end | |
def play | |
song_selection = input | |
begin | |
song_selection = Integer(song_selection) | |
rescue | |
end | |
if song_selection.is_a?(Integer) | |
puts "Playing #{@@songs[song_selection.to_i-1]}..." | |
# puts "Playing ..." | |
else | |
puts song_selection if songs.include?(song_selection) | |
end | |
end | |
end | |
binding.pry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment