lib/quran/audio/mp3.rb in quran-audio-0.3.1 vs lib/quran/audio/mp3.rb in quran-audio-0.3.2

- old
+ new

@@ -1,33 +1,46 @@ # frozen_string_literal: true module Quran::Audio - class MP3 < Struct.new(:author, :surah, :ayah, :bitrate, keyword_init: true) - def initialize(author:, **kw) - super(author: authors[author], **kw) + ## + # {Quran::Audio::MP3 Quran::Audio::MP3} provides + # an abstract interface around an MP3 file, and + # within the context of the quran-audio project. + class MP3 < Struct.new(:recitation, :surah, :ayah, :bitrate, keyword_init: true) + def initialize(recitation:, **kw) + super(recitation: recitations[recitation], **kw) end + ## + # @return [String] + # Returns the bitrate of an MP3 file def bitrate - super || author.default_bitrate + super || recitation.default_bitrate end + ## + # @return [String] + # Returns the path to an MP3 file on a remote HTTP server def remote_path filename = [surah.to_s.rjust(3, "0"), ayah.to_s.rjust(3, "0"), ".mp3"].join - File.join format(author.remote_path, bitrate:), filename + File.join format(recitation.remote_path, bitrate:), filename end + ## + # @return [String] + # Returns the path to an MP3 file on disk def local_path File.join( - format(author.dest_dir, sharedir:), + format(recitation.dest_dir, sharedir:), surah.to_s, "#{ayah}.mp3" ) end private - def authors - @authors ||= Ryo.from_json(path: File.join(datadir, "authors.json")) + def recitations + @recitations ||= Ryo.from_json(path: File.join(datadir, "recitations.json")) end def sharedir @sharedir ||= begin localbase = File.join(Dir.home, ".local")