Class: TrackList::DirectoryParser

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(dir) ⇒ DirectoryParser

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

Parameters:

  • dir (String)

    The directory to be parsed.



15
16
17
# File 'lib/track_list/directory_parser.rb', line 15

def initialize(dir)
    @dir = dir
end

Instance Method Details

#listArray

This method gets a list of files to be parsed.

Returns:

  • (Array)

    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

#parseArray

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.

Returns:

  • (Array)

    of TrackList::TrackParser objects.



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