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
-
.from_native(country_code, ctx) ⇒ String
Given a two-char country code as int, decodes it to a string.
-
.to_native(country_code, ctx) ⇒ Integer
Given a two-char country code, encodes it to an integer.
Class Method Details
.from_native(country_code, ctx) ⇒ String
Given a two-char country code as int, decodes it to a 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.
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 |