Module: Spotify::Util

Defined in:
lib/spotify/util.rb

Overview

Public utility helper methods.

Class Method Summary collapse

Class Method Details

.enum_value!(symbol, type) ⇒ Integer

Retrieves the associated value of an enum from a given symbol, raising an error if it does not exist.

Examples:

retrieving a value

Spotify::Util.enum_value!(:ok, "error value") # => 0

failing to retrieve a value

Spotify::Util.enum_value!(:moo, "connection rule") # => ArgumentError, invalid connection rule: :moo

Parameters:

  • symbol (Symbol)
  • type (#to_s)

    used as error message when the symbol does not resolve

Returns:

  • (Integer)

Raises:

  • (ArgumentError)

    when the symbol does not exist as an enum value



19
20
21
# File 'lib/spotify/util.rb', line 19

def enum_value!(symbol, type)
  Spotify::API.enum_value(symbol) or raise ArgumentError, "invalid #{type}: #{symbol.inspect}"
end

.linux?Boolean

Returns true if on Linux.

Returns:

  • (Boolean)

    true if on Linux

See Also:



26
27
28
# File 'lib/spotify/util.rb', line 26

def linux?
  platform == :linux
end

.platformSymbol

Returns platform as either :mac, :windows, or :linux.

Returns:

  • (Symbol)

    platform as either :mac, :windows, or :linux



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/spotify/util.rb', line 32

def platform
  case FFI::Platform::OS
  when /darwin/ then :mac
  when /linux/  then :linux
  when /windows/  then :windows
  else
    $stderr.puts "[WARN] You are running the Spotify gem on an unknown platform. (#{__FILE__}:#{__LINE__})"
    $stderr.puts "[WARN] Platform: #{FFI::Platform::OS}"
    :unknown
  end
end