Sha256: 9639ea34a864c7a815e606701bd6814685e5da60f2d279f092735441f6ba32f7

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# 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)
    end

    def bitrate
      super || author.default_bitrate
    end

    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
    end

    def local_path
      File.join(
        format(author.dest_dir, sharedir:),
        surah.to_s,
        "#{ayah}.mp3"
      )
    end

    private

    def authors
      @authors ||= Ryo.from_json(path: File.join(datadir, "authors.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(
        __dir__, "..", "..", "..",
        "share", "quran-audio", "data"
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quran-audio-0.3.1 lib/quran/audio/mp3.rb