Skip to content

Instantly share code, notes, and snippets.

@ahimmelstoss
Created October 8, 2013 15:34
Show Gist options
  • Save ahimmelstoss/6886592 to your computer and use it in GitHub Desktop.
Save ahimmelstoss/6886592 to your computer and use it in GitHub Desktop.
songs = {
"The Phoenix - 1901" => "https://www.youtube.com/watch?v=gvss3uhSKjw",
"Tokyo Police Club - Wait Up" => "https://www.youtube.com/watch?v=ZAxRozTgoXM",
"Sufjan Stevens - Too Much" => "https://www.youtube.com/watch?v=K0g7R3xqdcM",
"The Naked and the Famous - Young Blood" => "https://www.youtube.com/watch?v=0YuSg4mts9E",
"(Far From) Home - Tiga" => "https://www.youtube.com/watch?v=jTwQbc9kkUc",
"The Cults - Abducted" => "https://www.youtube.com/watch?v=9i1MXHGB8g0",
"The Phoenix - Consolation Prizes" => "https://www.youtube.com/watch?v=gnkVUReUVpQ"
}
class Jukebox
attr_accessor :songs
def initialize(songs)
@songs = songs
end
def call
instructions
loop do
user_input = gets.chomp
case user_input
when "help"
instructions
when "list"
list
puts
puts "Type 'play' to select a song."
when "play"
list
play
break #the play loop returns here and then breaks to exit program
when "exit"
puts "Goodbye!"
system("say goodbye")
break
else
puts "Invalid input. Please type 'help' for instructions."
system("say invalid input")
end
end
end
def instructions
puts "Welcome to Team Middle's Object Oriented Jukebox!"
system("say welcome to team middles object oriented jukebox")
puts "-- Type 'help' to get instructions."
puts "-- Type 'list' to see list of songs."
puts "-- Type 'play' to select a song."
puts "-- Type 'exit' turn off jukebox."
end
def play
puts "What song would you like to play?"
system("say what song would you like to play")
puts "Please type in a song title."
loop do
song_selection = gets.chomp
case song_selection.downcase
when "list"
list
when "help"
instructions
when "exit"
return "exit"
else
you_tube(suggester(song_selection.downcase))
puts "Playing #{suggester(song_selection.downcase)}"
system("say playing #{suggester(song_selection.downcase)}")
end
end
end
def list
self.songs.keys.each_with_index do |song, i|
puts "#{i+1}. #{song}"
end
end
def suggester(test)
self.songs.keys.each do |each_song|
match_chars = each_song.split(" - ").last.chars.select do |char|
test.chars.include?(char)
end
if match_chars.length > test.length/2
return each_song
end
end
puts "Invalid entry"
end
def you_tube(suggester)
self.songs[suggester]
system("open -g #{self.songs[suggester]}")
end
end
team_middle = Jukebox.new(songs)
team_middle.call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment