Module: Edoxen::ReferenceData

Defined in:
lib/edoxen/reference_data.rb,
sig/edoxen.rbs

Overview

Built-in reference data for ISO codes used across the Edoxen model: ISO 3166-1 alpha-2 country codes, ISO 639-3 language codes, ISO 15924 script codes, UN/LOCODEs, and IATA airport codes.

UN/LOCODE lookups delegate to the unlocodes gem (the canonical Ruby registry of the UNECE UN/LOCODE dataset). IATA lookups delegate to the iata gem (the canonical Ruby registry of the IATA airport code list, sourced from Wikidata).

Reference data sources:

Constant Summary collapse

COUNTRY_CODES =
%w[
  AE AF AR AT AU BE BG BR BY CA CH CL CN CO CY CZ DE DK EE ES FI FR
  GB GR HK HR HU ID IE IL IN IS IT JP KE KR LK LT LU LV MT MX MY NL NO PH
  NZ PL PT RO RS RU SA SE SG SI SK TH TN TR TW UA US VN ZA
].freeze
LANGUAGE_CODES =
%w[
  ara chi deu eng fra jpn rus spa zho
].freeze
SCRIPT_CODES =
%w[
  Arab Cyrl Hans Hant Hang Hebr Jpan Kore Latn
].freeze
UNLOCODES =
%w[
  AUMEL ATVIE BEBRU BGSOF BRBSB CHGVA CNCAN CNHKG CNSHA CNXSZ COCTG
  CYLCA CZPRG DEBER DEHAM DEFRA DKCPH ESMAD FIHEL FRARC FRLYS FRMRS
  FRPAR GBLON HKHKG HUBUD IDJKT IEDUB IEORK ILTLV INDEL ISREY ITROM
  JPTYO KEMBA KRSEL LKCMB LVRIX LULUX MYKUL NLRTM NOOSL NZAKL PHMNL
  PLWAW PTLIS ROBUH RSBEG SESTO SGSIN SKBTS THBKK THCNM TRIST TWTPE
  UAIEV USMIA USNYC USORL VNSGN ZACPT
].freeze
CITY_CODES =
Deprecated.

Use UNLOCODES. Retained for one release to ease

migration; will be removed in the next minor.

UNLOCODES

Class Method Summary collapse

Class Method Details

.find_iata(code) ⇒ Iata::Entry?

Look up an IATA airport/city code via the canonical iata gem.

Parameters:

  • code (String, #to_s)

    3-character IATA code

Returns:

  • (Iata::Entry, nil)


80
81
82
# File 'lib/edoxen/reference_data.rb', line 80

def find_iata(code)
  iata_registry.find(code.to_s.upcase)
end

.find_unlocode(code) ⇒ Unlocodes::Entry?

Look up a UN/LOCODE entry via the canonical unlocodes gem.

Parameters:

  • code (String, #to_s)

    5-character UN/LOCODE

Returns:

  • (Unlocodes::Entry, nil)


69
70
71
# File 'lib/edoxen/reference_data.rb', line 69

def find_unlocode(code)
  unlocodes_registry.find(code.to_s.upcase)
end

.iata_exists?(code) ⇒ Boolean

Parameters:

  • code (String)

Returns:

  • (Boolean)


84
85
86
# File 'lib/edoxen/reference_data.rb', line 84

def iata_exists?(code)
  !find_iata(code).nil?
end

.iata_registryIata::Registry

Returns:

  • (Iata::Registry)


62
63
64
# File 'lib/edoxen/reference_data.rb', line 62

def iata_registry
  @iata_registry ||= Iata::Registry.load_default
end

.unlocode_exists?(code) ⇒ Boolean

Parameters:

  • code (String)

Returns:

  • (Boolean)


73
74
75
# File 'lib/edoxen/reference_data.rb', line 73

def unlocode_exists?(code)
  !find_unlocode(code).nil?
end

.unlocodes_registryUnlocodes::Registry

Returns:

  • (Unlocodes::Registry)


57
58
59
# File 'lib/edoxen/reference_data.rb', line 57

def unlocodes_registry
  @unlocodes_registry ||= Unlocodes::Registry.load_default
end