Module: Spotify::CountryCode

Extended by:
FFI::DataConverter
Defined in:
lib/spotify/data_converters/country_code.rb

Overview

A type for converting a country code to an int, and vice versa.

Constant Summary collapse

PACK_FORMAT =

String#pack format used by libspotify for storing country code.

"s>"

Class Method Summary collapse

Class Method Details

.from_native(country_code, ctx) ⇒ String

Given a two-char country code as int, decodes it to a string.

Parameters:

  • country_code (Integer)
  • ctx

Returns:

  • (String)

    country code as string



25
26
27
# File 'lib/spotify/data_converters/country_code.rb', line 25

def from_native(country_code, ctx)
  [country_code].pack(PACK_FORMAT)
end

.to_native(country_code, ctx) ⇒ Integer

Given a two-char country code, encodes it to an integer.

Parameters:

  • country_code (String, nil)
  • ctx

Returns:

  • (Integer)

    country code as int



16
17
18
# File 'lib/spotify/data_converters/country_code.rb', line 16

def to_native(country_code, ctx)
  country_code.unpack(PACK_FORMAT)[0]
end