Class: Awaaz::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/awaaz/config.rb

Overview

The Config class handles detection and configuration of available audio decoders for the Awaaz gem. It checks the system for supported decoder binaries (mpg123, ffmpeg, sox) and provides query helpers to check their availability.

Examples:

Check if ‘ffmpeg` is available

Awaaz.config.ffmpeg? # => true or false

Instance Method Summary collapse

Constructor Details

#initializeConfig

Creates a new configuration instance and detects available decoders.



20
21
22
# File 'lib/awaaz/config.rb', line 20

def initialize
  @available_decoders = detect_decoders
end

Instance Method Details

#decoder?(name) ⇒ Boolean

Checks if a given decoder is available on the system.

Parameters:

  • name (Symbol, String)

    The name of the decoder (e.g., ‘:mpg123`, `“ffmpeg”`).

Returns:

  • (Boolean)

    ‘true` if the decoder is available, otherwise `false`.



30
31
32
# File 'lib/awaaz/config.rb', line 30

def decoder?(name)
  @available_decoders.include?(name.to_sym)
end

#decoders_for_wav?Boolean

Checks if there is at least one decoder capable of handling WAV files.

Currently, ‘ffmpeg` and `sox` are considered capable of decoding WAV files.

Returns:

  • (Boolean)

    ‘true` if either `ffmpeg` or `sox` is available, otherwise `false`.



86
87
88
# File 'lib/awaaz/config.rb', line 86

def decoders_for_wav?
  ffmpeg? || sox?
end

#ffmpeg?Boolean

Checks if ffmpeg is available.

Returns:

  • (Boolean)

    ‘true` if ffmpeg is installed, otherwise `false`.



48
49
50
# File 'lib/awaaz/config.rb', line 48

def ffmpeg?
  decoder?(:ffmpeg)
end

#mpg123?Boolean

Checks if mpg123 is available.

Returns:

  • (Boolean)

    ‘true` if mpg123 is installed, otherwise `false`.



39
40
41
# File 'lib/awaaz/config.rb', line 39

def mpg123?
  decoder?(:mpg123)
end

#no_decoders?Boolean

Checks if no decoders are available on the system.

Returns:

  • (Boolean)

    ‘true` if no decoders were detected, otherwise `false`.



75
76
77
# File 'lib/awaaz/config.rb', line 75

def no_decoders?
  @available_decoders.nil? || @available_decoders.empty?
end

#no_decoders_for_wav?Boolean

Checks if there are no decoders available for handling WAV files.

This is the logical negation of #decoders_for_wav?.

Returns:

  • (Boolean)

    ‘true` if neither `ffmpeg` nor `sox` is available, otherwise `false`.



97
98
99
# File 'lib/awaaz/config.rb', line 97

def no_decoders_for_wav?
  !decoders_for_wav?
end

#potential_decodersArray<Symbol>

Lists all potential decoders that Awaaz can work with.

Returns:

  • (Array<Symbol>)

    An array of decoder names (‘:mpg123`, `:ffmpeg`, `:sox`).



66
67
68
# File 'lib/awaaz/config.rb', line 66

def potential_decoders
  %i[mpg123 ffmpeg sox]
end

#sox?Boolean

Checks if sox is available.

Returns:

  • (Boolean)

    ‘true` if sox is installed, otherwise `false`.



57
58
59
# File 'lib/awaaz/config.rb', line 57

def sox?
  decoder?(:sox)
end