Class: Iata::Loader
- Inherits:
-
Object
- Object
- Iata::Loader
- 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
- .load_file(path) ⇒ Array<Iata::Entry>
- .load_json(json) ⇒ Array<Iata::Entry>
- .parse(data) ⇒ Array<Iata::Entry>
Class Method Details
.load_file(path) ⇒ Array<Iata::Entry>
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>
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>
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 |