Module: YandexSpeechApi::Helpers

Defined in:
lib/yandex_speech/helpers.rb

Class Method Summary collapse

Class Method Details

.find_executable(cmd) ⇒ Pathname, NilClass

Searches pathname for executable cmd.

Returns:

  • (Pathname, NilClass)

    Returns Pathname if cmd is present and executable. If search unsuccessful it returns nil.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/yandex_speech/helpers.rb', line 38

def self.find_executable(cmd)
  possible_extensions = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']

  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    possible_extensions.each do |extension|
      exe = Pathname.new(File.join(path, "#{cmd}#{extension}"))

      return exe if exe.executable? && exe.file?
    end
  end

  return nil # search unsuccessful
end

.recognize_operation_systemSymbol

From what OS we launched?

Examples:

#1

recognize_operation_system # ==> :linux

#2

recognize_operation_system # ==> :unknown

Returns:

  • (Symbol)

    OS name



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yandex_speech/helpers.rb', line 18

def self.recognize_operation_system
  case RbConfig::CONFIG['host_os']
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
    :windows
  when /darwin|mac os/
    :mac_os
  when /linux/
    :linux
  else
    :unknown
  end
end