From 25d45f6b38360b071dca2ec1fbd0613d34bcd983 Mon Sep 17 00:00:00 2001 From: Zion <106357206+ZionMiller@users.noreply.github.com> Date: Tue, 8 Nov 2022 08:04:06 -0800 Subject: [PATCH] added travel folder and airports (#2601) * added travel folder and airports. I often find myself creating these seeds and would love the addition to Faker to help save time on travel apps. This commit contains us and eu airports by size and iata code * Update test/faker/travel/test_faker_airports.rb Co-authored-by: Stefanni Brasil * Update lib/faker/travel/airport.rb Co-authored-by: Thiago Araujo * Update lib/faker/travel/airport.rb Co-authored-by: Thiago Araujo * added continent/region argument to generator, this works by name || iata code * fixed white space issue for rubocop * refactored airport md to 2 methods name or iata, both take arguments size && region, provided some rescue for method, and added generator to README Co-authored-by: Stefanni Brasil Co-authored-by: Thiago Araujo --- README.md | 3 + doc/travel/airport.md | 6 + lib/faker/travel/airport.rb | 47 +++ lib/locales/en/airport.yml | 382 +++++++++++++++++++++++ test/faker/travel/test_faker_airports.rb | 17 + 5 files changed, 455 insertions(+) create mode 100644 doc/travel/airport.md create mode 100644 lib/faker/travel/airport.rb create mode 100644 lib/locales/en/airport.yml create mode 100644 test/faker/travel/test_faker_airports.rb diff --git a/README.md b/README.md index 78aaf7c915..f90ead4a53 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,9 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main ### Fantasy - [Faker::Fantasy::Tolkien](doc/fantasy/tolkien.md) +### Travel + - [Faker:Travel::Airport](doc/travel/airport.md) + ### Creature - [Faker::Creature::Animal](doc/creature/animal.md) - [Faker::Creature::Bird](doc/creature/bird.md) diff --git a/doc/travel/airport.md b/doc/travel/airport.md new file mode 100644 index 0000000000..a45dbba156 --- /dev/null +++ b/doc/travel/airport.md @@ -0,0 +1,6 @@ +# Faker::Travel::Airport + +```ruby +Faker::Movies::Travel::Airport.name('large', 'united_states') #=> "Los Angeles International Airport" +Faker::Movies::Travel::Airport.iata('large', 'united_states') #=> "LAX" +``` \ No newline at end of file diff --git a/lib/faker/travel/airport.rb b/lib/faker/travel/airport.rb new file mode 100644 index 0000000000..3afd2eb670 --- /dev/null +++ b/lib/faker/travel/airport.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Faker + class Travel + class Airport < Base + class << self + ## + # Produces random Airport by name and takes arguments for size and region + # + # @param size [String] airport size, united_states has large, or medium, or small, european_union has large, or medium + # + # @param region [String] airport region, currently available -> united_states or european_union + # + # @retrun [String] + # + # @example + # Faker::Travel::Airport.name('large', 'united_states') => "Los Angeles International Airport" + # + # @faker.version next + def name(size, region) + fetch("airport.#{region}.#{size}") + rescue I18n::MissingTranslationData + p 'valid arguments are size && region -> US has size large medium small, EU has size large medium -- united_states || european_union' + end + + ## + # Produces random Airport by IATA code and takes arguments for size and region + # + # @param size [String] airport size, united_states has large, or medium, or small, european_union has large, or medium + # + # @param region [String] airport region, currently available -> united_states or european_union + # + # @retrun [String] + # + # @example + # Faker::Travel::Airport.iata('large', 'united_states') => "LAX" + # + # @faker.version next + def iata(size, region) + fetch("airport.#{region}.iata_code.#{size}") + rescue I18n::MissingTranslationData + p 'valid arguments are size && region -> US has size large medium small, EU has size large medium -- united_states || european_union' + end + end + end + end +end diff --git a/lib/locales/en/airport.yml b/lib/locales/en/airport.yml new file mode 100644 index 0000000000..0270fee333 --- /dev/null +++ b/lib/locales/en/airport.yml @@ -0,0 +1,382 @@ +en: + faker: + airport: + united_states: + large: + - Hartsfield Jackson Atlanta International Airport + - Baltimore/Washington International Airport + - Logan International Airport + - Charlotte Douglas International Airport + - Midway International Airport + - O'Hare International Airport + - Dallas/Fort Worth International Airport + - Denver International Airport + - Detroit Metropolitan Airport + - Fort Lauderdale Hollywood International Airport + - Daniel K. Inouye International Airport + - George Bush Intercontinental Airport + - Harry Reid International Airport + - Los Angeles International Airport + - Miami International Airport + - Minneapolis Saint Paul International Airport + - John F. Kennedy International Airport + - LaGuardia Airport + - Newark Liberty International Airport + - Orlando International Airport + - Philadelphia International Airport + - Phoenix Sky Harbor International Airport + - Portland International Airport + - Salt Lake City International Airport + - San Diego International Airport + - San Francisco International Airport + - Seattle Tacoma International Airport + - Tampa International Airport + - Ronald Reagan Washington National Airport** + - Dulles International Airport + medium: + - Albuquerque International Sunport + - Ted Stevens Anchorage International Airport + - Austin Bergstrom International Airport + - Boise Airport + - Buffalo Niagara International Airport + - Charleston International Airport + - Cincinnati/Northern Kentucky International Airport + - Cleveland Hopkins International Airport + - John Glenn Columbus International Airport + - El Paso International Airport + - Southwest Florida International Airport + - Gerald R. Ford International Airport + - Bradley International Airport + - William P. Hobby Airport + - Indianapolis International Airport + - Jacksonville International Airport + - Kansas City International Airport + - Louisville Muhammad Ali International Airport + - Memphis International Airport + - General Mitchell International Airport + - Nashville International Airport + - Louis Armstrong New Orleans International Airport + - Norfolk International Airport + - Oakland International Airport + - Will Rogers World Airport + - Eppley Airfield + - Ontario International Airport + - John Wayne Airport + - Northwest Florida Beaches International Airport + - Pittsburgh International Airport + - Rhode Island T. F. Green International Airport + - Raleigh Durham International Airport + - Reno Tahoe International Airport + - Richmond International Airport + - Sacramento International Airport + - San Antonio International Airport + - San Jose International Airport + - Spokane International Airport + - St. Louis Lambert International Airport + - Palm Beach International Airport + small: + - Albany International Airport + - Appleton International Airport + - Atlantic City International Airport + - Bellingham International Airport + - Birmingham Shuttlesworth International Airport + - Dayton International Airport + - Des Moines International Airport + - Fairbanks International Airport + - Fresno Yosemite International Airport + - Green Bay Austin Straubel International Airport + - Piedmont Triad International Airport + - Harrisburg International Airport + - Hilo International Airport + - Huntsville International Airport + - Jackson Medgar Wiley Evers International Airport + - Key West International Airport + - Kona International Airport + - McGhee Tyson Airport + - Clinton National Airport + - Midland International Air and Space Port + - Myrtle Beach International Airport + - Stewart International Airport + - Orlando Sanford International Airport + - Palm Springs International Airport + - Pensacola International Airport + - Phoenix Mesa Gateway Airport + - Portland International Jetport + - Batten International Airport + - Greater Rochester International Airport + - Sarasota Bradenton International Airport + - Savannah/Hilton Head International Airport + - St. Pete Clearwater International Airport + - Syracuse Hancock International Airport + - Tallahassee International Airport + - Tucson International Airport + - Tulsa International Airport + - Wilkes-Barre/Scranton International Airport + - Wilmington International Airport + iata_code: + large: + - ATL + - BWI + - BOS + - CLT + - MDW + - ORD + - DFW + - DEN + - DTW + - FLL + - HNL + - IAH + - LAS + - LAX + - MIA + - MSP + - JFK + - LGA + - EWR + - MCO + - PHL + - PHX + - PDX + - SLC + - SAN + - SFO + - SEA + - TPA + - DCA + - IAD + medium: + - ABQ + - ANC + - AUS + - BOI + - BUF + - CHS + - CVG + - CLE + - CMH + - ELP + - RSW + - GRR + - BDL + - HOU + - IND + - JAX + - MCI + - SDF + - MEM + - MKE + - BNA + - MSY + - ORF + - OAK + - OKC + - OMA + - ONT + - SNA + - ECP + - PIT + - PVD + - RDU + - RNO + - RIC + - SMF + - SAT + - SJC + - GEG + - STL + - PBI + small: + - ALB + - ATW + - ACY + - BLI + - BHM + - DAY + - DSM + - FAI + - FAT + - GRB + - GSO + - MDT + - ITO + - HSV + - JAN + - EYW + - KOA + - TYS + - LIT + - MAF + - MYR + - SWF + - SFB + - PSP + - PNS + - AZA + - PWM + - RAC + - ROC + - SRQ + - SAV + - PIE + - SYR + - TLH + - TUS + - TUL + - AVP + - ILM + european_union: + large: + - Gatwick Airport + - Heathrow Airport + - Luton Airport + - London Southend Airport + - London Stansted Airport + - Manchester Airport + - Charles de Gaulle Airport + - Orly Airport + - Amsterdam Airport Schiphol + - Karlsruhe/Baden-Baden Airport + - Berlin Brandenburg Airport + - Düsseldorf Airport + - Frankfurt Airport + - Munich Airport + - Josep Tarradellas Barcelona El Prat Airport + - Madrid-Barajas Airport + - Palma de Mallorca Airport + - Milan Malpensa Airport + - Leonardo da Vinci Fiumicino Airport + - Athens International Airport + - Oslo Airport, Gardermoen + - Stockholm Arlanda Airport + medium: + - Birmingham Airport + - Bristol Airport + - Liverpool John Lennon Airport + - London City Airport + - Luton Airport + - Newcastle Airport + - East Midlands Airport + - Aberdeen Airport + - Edinburgh Airport + - Glasgow International Airport + - Belfast International Airport + - Beauvais Tillé Airport + - Bordeaux Mérignac Airport + - Lyon Saint Exupéry Airport + - Marseille Provence Airport + - EuroAirport Basel Mulhouse Freiburg + - Nantes Atlantique Airport + - Nice Côte d'Azur Airport + - Toulouse Blagnac Airport + - Vienna International Airport + - Findel Airport + - Dublin Airport + - Václav Havel Airport Prague + - Karlsruhe/Baden-Baden Airport + - Cologne/Bonn Airport + - EuroAirport Basel Mulhouse Freiburg + - Hamburg Airport + - Hannover Airport + - Stuttgart Airport + - Budapest Ferenc Liszt International Airport + - Bratislava Airport + - Zurich Airport + - Kraków John Paul II International Airport + - Alicante Elche Miguel Hernández Airport + - Bilbao Airport + - Fuerteventura Airport + - Gran Canaria Airport + - Ibiza Airport + - Lanzarote Airport + - Málaga Airport + - Seville Airport + - Tenerife North Ciudad de La Laguna Airport + - Tenerife South Airport + - Valencia Airport + - Lisbon Airport + - Palese Airport + - Orio al Serio Airport + - Bologna Airport + - Cagliari Airport + - Fontanarossa Airport + - Linate Airport + - Naples International Airport + iata_code: + large: + - LGW + - LHR + - LTN + - SEN + - STN + - MAN + - CDG + - ORY + - AMS + - FKB + - BER + - DUS + - FRA + - MUC + - BCN + - MAD + - PMI + - MXP + - FCO + - ATH + - OSL + - ARN + medium: + - BHX + - BRS + - LPL + - LCY + - LTN + - NCL + - EMA + - ABZ + - EDI + - GLA + - BFS + - BVA + - BOD + - LYS + - MRS + - BSL + - NTE + - NCE + - TLS + - VIE + - LUX + - DUB + - PRG + - FKB + - CGN + - MLH/BSL/EAP + - HAM + - HAJ + - STR + - BUD + - BTS + - ZRH + - KRK + - ALC + - BIO + - FUE + - LPA + - IBZ + - ACE + - AGP + - SVQ + - TFN + - TFS + - VLC + - LIS + - BRI + - BGY + - BLQ + - CAG + - CTA + - LIN + - NAP + \ No newline at end of file diff --git a/test/faker/travel/test_faker_airports.rb b/test/faker/travel/test_faker_airports.rb new file mode 100644 index 0000000000..957d713334 --- /dev/null +++ b/test/faker/travel/test_faker_airports.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerAirport < Test::Unit::TestCase + def setup + @tester = Faker::Travel::Airport + end + + def name + assert_match(/\w+/, @tester.name) + end + + def iata + assert_match(/\w+/, @tester.iata) + end +end