Advertisement
Guest User

fmlplayer

a guest
Apr 2nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.89 KB | None | 0 0
  1. # reads in a single track from the given file.
  2. def read_album a_file
  3.   title = a_file.gets()
  4.   artist = a_file.gets()
  5.   genre = a_file.gets()
  6.   tracks = a_file.gets()
  7.   count = tracks.to_i
  8.  
  9.   count.times do
  10.     read_track (a_file)
  11.   end
  12.   return Album.new(title, artist, genre, tracks)
  13. end
  14.  
  15. # Returns an array of tracks read from the given file
  16. def read_albums music_file
  17.   count = music_file.gets().to_i
  18.   albums = Array.new
  19.   i = 0
  20.   # Put a while loop here which increments an index to read the tracks
  21.   while i < count
  22.     album = read_album(music_file)
  23.     albums << album
  24.     i += 1
  25.   end
  26.  
  27.   return albums    
  28. end
  29.  
  30. main
  31.     #calling a file albums
  32.     a_file = File.new("albums.txt", "r")
  33.     temp_albums = read_albums(a_file).to_s
  34.     #in this line i want to access the element albums thats returned from above method read_albums
  35.     puts $genre_names[temp_albums.genre]
  36. end
  37.  
  38. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement