Class: Iata::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/iata/loader.rb

Overview

Parses the bundled IATA airport JSON file into Entry instances.

File format:

{
"_meta": {
  "fetched_at": "2026-07-02T12:00:00Z",
  "source": "Wikidata (P238)",
  "count": 12345
},
"PVG": {
  "code": "PVG",
  "name": "Shanghai Pudong International Airport",
  "wikidata_id": "Q86792",
  "country_iso2": "CN",
  "country_name": "China",
  "latitude": 31.1434,
  "longitude": 121.8052
},
...
}

Class Method Summary collapse

Class Method Details

.load_file(path) ⇒ Array<Iata::Entry>

Parameters:

  • path (String)

Returns:



32
33
34
# File 'lib/iata/loader.rb', line 32

def load_file(path)
  load_json(File.read(path))
end

.load_json(json) ⇒ Array<Iata::Entry>

Parameters:

  • json (String)

Returns:



38
39
40
# File 'lib/iata/loader.rb', line 38

def load_json(json)
  parse(JSON.parse(json, symbolize_names: false))
end

.parse(data) ⇒ Array<Iata::Entry>

Parameters:

  • data (Hash)

Returns:



44
45
46
47
# File 'lib/iata/loader.rb', line 44

def parse(data)
  entries = data.is_a?(Hash) ? data.except('_meta') : {}
  entries.map { |_code, attrs| build_entry(attrs) }
end