Sha256: 76b0ef99e2396f1aa071e6f3f50a95cf05f3ac1c9e5583a1c0aaf9bae496addf

Contents?: true

Size: 572 Bytes

Versions: 2

Compression:

Stored size: 572 Bytes

Contents

require 'songbooks/song'

module Songbooks
  class Folder
    def initialize(path)
      @path = Pathname.new(path)
    end

    attr_reader :path

    def song(identifier)
      songs_by_identifier[identifier]
    end

    def songs
      songs_by_identifier.values
    end

    private

    def songs_by_identifier
      @songs ||= chords_files.each_with_object({}) do |file_path, h|
        song = Songbooks::Song.new(File.read(file_path))
        h[song.identifier] = song
      end
    end

    def chords_files
      Dir[@path.join('**', '*.txt')]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
songbooks-0.1.1 lib/songbooks/folder.rb
songbooks-0.1.0 lib/songbooks/folder.rb