Class: TrackList::DirectoryParser
- Inherits:
-
Object
- Object
- TrackList::DirectoryParser
- Defined in:
- lib/track_list/directory_parser.rb
Overview
This class is a helper to parse through an entire directory of tracks and return an array of parsed, formatted tracks.
Instance Method Summary collapse
-
#initialize(dir) ⇒ DirectoryParser
constructor
When initializing the class, pass in a directory with audio files to be parsed.
-
#list ⇒ Array
This method gets a list of files to be parsed.
-
#parse ⇒ Array
This method does the bulk of the work.
Constructor Details
#initialize(dir) ⇒ DirectoryParser
When initializing the class, pass in a directory with audio files to be parsed.
15 16 17 |
# File 'lib/track_list/directory_parser.rb', line 15 def initialize(dir) @dir = dir end |
Instance Method Details
#list ⇒ Array
This method gets a list of files to be parsed.
23 24 25 26 27 28 29 |
# File 'lib/track_list/directory_parser.rb', line 23 def list files = [] Dir.foreach(@dir) do |file| files.push(@dir + '/' + file) end return files end |
#parse ⇒ Array
This method does the bulk of the work. It loops over each of the files we got in self.list
and returns an array of TrackList::TrackParser
objects to be looped over elsewhere.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/track_list/directory_parser.rb', line 37 def parse files = self.list.sort parsed_tracks = [] files.each do |filename, index| track = TrackList::TrackParser.new(filename) if track != nil || track != '' parsed_tracks.push(track) end end return parsed_tracks end |