Class: Ffprober::Ffmpeg::Finder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ffprober/ffmpeg/finder.rb

Constant Summary collapse

SEARCH_PATHS =
T.let(ENV['PATH'], T.nilable(String))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFinder

Returns a new instance of Finder.



14
15
16
17
18
# File 'lib/ffprober/ffmpeg/finder.rb', line 14

def initialize
  @executable_path = T.let(nil, T.nilable(String))
  @executable_name = T.let(executable_name_picker, String)
  @path = T.let(nil, T.nilable(String))
end

Instance Attribute Details

#executable_nameObject (readonly)

Returns the value of attribute executable_name.



11
12
13
# File 'lib/ffprober/ffmpeg/finder.rb', line 11

def executable_name
  @executable_name
end

Instance Method Details

#executable_name_pickerObject



33
34
35
36
37
38
39
# File 'lib/ffprober/ffmpeg/finder.rb', line 33

def executable_name_picker
  if windows?
    T.let('ffprobe.exe', String)
  else
    T.let('ffprobe', String)
  end
end

#executable_pathObject



42
43
44
45
46
47
48
# File 'lib/ffprober/ffmpeg/finder.rb', line 42

def executable_path
  @executable_path ||= begin
    T.must(SEARCH_PATHS).split(File::PATH_SEPARATOR).detect do |path_to_check|
      File.executable?(File.join(path_to_check, executable_name))
    end
  end
end

#pathObject



21
22
23
24
25
# File 'lib/ffprober/ffmpeg/finder.rb', line 21

def path
  raise Ffprober::NoFfprobeFound, 'ffprobe executable not found' if executable_path.nil?

  @path ||= File.expand_path(executable_name, executable_path)
end

#windows?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ffprober/ffmpeg/finder.rb', line 28

def windows?
  !(RUBY_PLATFORM =~ /(mingw|mswin)/).nil?
end