random-flight-generator
Version:
A tool for generating random flights.
87 lines (86 loc) • 3.13 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Airport = void 0;
var Country_1 = require("./Country");
var Airport = /** @class */ (function () {
function Airport(airport) {
this.icao = '';
this.iata = '';
this.lat = 0;
this.lon = 0;
this.name = '';
this.country = '';
this.state = '';
this.city = '';
this.elevation = 0;
this.randomlyGenerated = false;
if (airport) {
this.icao = airport.icao;
this.iata = airport.iata;
this.lat = airport.lat;
this.lon = airport.lon;
this.name = airport.name;
this.country = airport.country;
this.state = airport.state;
this.city = airport.city;
this.elevation = airport.elevation;
}
else {
this.randomlyGenerated = true;
}
}
Airport.prototype.getCountryName = function () {
return new Country_1.Country(this.country).getName();
};
Airport.prototype.getState = function () {
return this.state.replace('-', ' ');
};
Airport.prototype.satisfiesFlightGeneratorOptions = function (options) {
var hasLatitude = !!this.lat;
var hasLongitude = !!this.lon;
var hasIcao = !!this.icao;
var includeCountries = true;
var excludeCountries = true;
var majorAirportsOnly = true;
if (options === null || options === void 0 ? void 0 : options.includeCountries) {
includeCountries = options.includeCountries.includes(this.country);
}
if (options === null || options === void 0 ? void 0 : options.excludeCountries) {
excludeCountries = !options.excludeCountries.includes(this.country);
}
if (options === null || options === void 0 ? void 0 : options.majorAirportsOnly) {
majorAirportsOnly = !!this.iata;
}
return (hasLatitude &&
hasLongitude &&
hasIcao &&
includeCountries &&
excludeCountries &&
majorAirportsOnly);
};
Airport.prototype.toJson = function () {
return {
icao: this.icao,
iata: this.iata,
lat: this.lat,
lon: this.lon,
name: this.name,
country: this.getCountryName(),
state: this.getState(),
city: this.city,
elevation: this.elevation,
randomlyGenerated: this.randomlyGenerated,
};
};
Airport.prototype.print = function () {
console.log("Name: " + this.name);
console.log("ICAO: " + this.icao);
console.log("IATA: " + this.iata);
console.log("Country: " + this.getCountryName() + " - " + this.country);
console.log("State: " + this.getState());
console.log("City: " + this.city);
console.log("Elevation: " + this.elevation + " feet");
};
return Airport;
}());
exports.Airport = Airport;