class TrackList::DirectoryParser

This class is a helper to parse through an entire directory of tracks and return an array of parsed, formatted tracks.

Public Class Methods

new(dir) click to toggle source

When initializing the class, pass in a directory with audio files to be parsed.

@param [String] dir The directory to be parsed.

# File lib/track_list/directory_parser.rb, line 15
def initialize(dir)
    @dir = dir
end

Public Instance Methods

list() click to toggle source

This method gets a list of files to be parsed.

@return [Array] Files to be parsed.

# 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() click to toggle source

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.

@return [Array] of TrackList::TrackParser objects.

# 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