Skip to content

Instantly share code, notes, and snippets.

@chhhris
Created June 10, 2013 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chhhris/5753393 to your computer and use it in GitHub Desktop.
Save chhhris/5753393 to your computer and use it in GitHub Desktop.
library {
:artist => {
"The Magnetic Fields" => {
"69 Love Songs" => ["Song 1", "Song 2"]
]
"Get Lost" => ["Song 1", "Song 2"]
}
"Netural Milk Hotel" => {
"In An Aeroplane Over the Sea" => ["Song 1", "Song 2"]
}
}
}
organized_library = Hash.new
songs.each do |song|
song_array = song.split("-")
artist = song_array[0].strip
album = song_array[1].strip
track = song_array[2].strip
organized_library[artist.to_sym] ||={}
organized_library[artist.to_sym] ||={album.to_sym} ||={}
organized_library[artist.to_sym] ||={album.to_sym} << track
# if organized_library[artist.to_sym] # weve seen this artist before
# if organized_library[artist.to_sym][album.to_sym] # weve seen this album before
# organized_library[artist.to_sym][album.to_sym] << track
# else
# organized_library[artist.to_sym][album.to_sym] = [track]
# end
# else
# organized_library[artist.to_sym] = {album.to_sym => [track]}
# end
end
puts organized_library.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment