lib/quran/audio/mp3.rb in quran-audio-0.3.3 vs lib/quran/audio/mp3.rb in quran-audio-0.4.0

- old
+ new

@@ -1,12 +1,11 @@ # frozen_string_literal: true module Quran::Audio ## - # {Quran::Audio::MP3 Quran::Audio::MP3} provides - # an abstract interface around an MP3 file, and - # within the context of the quran-audio project. + # {Quran::Audio::MP3 Quran::Audio::MP3} represents + # an ayah of The Noble Quran in the MP3 format. class MP3 < Struct.new(:recitation, :surah, :ayah, :bitrate, keyword_init: true) def initialize(recitation:, **kw) super(recitation: recitations[recitation], **kw) end @@ -17,14 +16,21 @@ super || recitation.default_bitrate end ## # @return [String] + # Returns the host of a remote HTTP server + def host + recitation.host + 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(recitation.path, bitrate:), filename + File.join format(recitation.path, bitrate:), + [surah, "/", ayah, ".mp3"].join end ## # @return [String] # Returns the path to an MP3 file on disk @@ -37,23 +43,23 @@ end private def recitations - @recitations ||= Ryo.from_json(path: File.join(datadir, "recitations.json")) + @recitations ||= Ryo.from_json(path: File.join(jsondir, "recitations.json")) end def sharedir @sharedir ||= begin localbase = File.join(Dir.home, ".local") File.join(localbase, "share", "quran-audio") end end - def datadir - @datadir ||= File.realpath File.join( + def jsondir + @jsondir ||= File.realpath File.join( __dir__, "..", "..", "..", - "share", "quran-audio", "data" + "share", "quran-audio", "json" ) end end end