Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
<summary>Travel</summary>

- [Faker:Travel::Airport](doc/travel/airport.md)
- [Faker::Travel::Airline](doc/travel/airline.md)
- [Faker:Travel::TrainStation](doc/travel/train_station.md)
</details>

Expand Down
6 changes: 6 additions & 0 deletions doc/travel/airline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Faker::Travel::Airline

```ruby
Faker::Travel::Airline.name(country_code: 'US') #=> "American Airlines"
Faker::Travel::Airline.iata(country_code: 'US') #=> "AA"
```
39 changes: 39 additions & 0 deletions lib/faker/travel/airline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module Faker
class Travel
class Airline < Base
class << self
##
# Produces random Airline by name and takes argument for country code
#
# @param country_code [String] two letter country code, i.e. US, CA, GB, DE, AE, QA, JP, AU, SG, etc.
#
# @return [String]
#
# @example
# Faker::Travel::Airline.name(country_code: 'US') => "American Airlines"
#
# @faker.version next
def name(country_code:)
fetch("airline.#{country_code}.name")
end

##
# Produces random Airline by IATA code and takes argument for country code
#
# @param country_code [String] two letter country code, i.e. US, CA, GB, DE, AE, QA, JP, AU, SG, etc.
#
# @return [String]
#
# @example
# Faker::Travel::Airline.iata(country_code: 'US') => "AA"
#
# @faker.version next
def iata(country_code:)
fetch("airline.#{country_code}.iata")
end
end
end
end
end
128 changes: 128 additions & 0 deletions lib/locales/en/airline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
en:
faker:
airline:
US:
name:
- American Airlines
- United Airlines
- Delta Air Lines
- Southwest Airlines
- Alaska Airlines
- JetBlue Airways
- Spirit Airlines
- Frontier Airlines
- Hawaiian Airlines
- Allegiant Air
iata:
- AA
- UA
- DL
- WN
- AS
- B6
- NK
- F9
- HA
- G4
CA:
name:
- Air Canada
- WestJet
- Air Transat
- Porter Airlines
- Flair Airlines
- Air North
- Canadian North
iata:
- AC
- WS
- TS
- PD
- F8
- 4N
- 5T
GB:
name:
- British Airways
- Virgin Atlantic
- easyJet
- Jet2
- TUI Airways
- Loganair
- Eastern Airways
iata:
- BA
- VS
- U2
- LS
- BY
- LM
- T3
DE:
name:
- Lufthansa
- Eurowings
- Condor
- TUI fly Deutschland
- Hahn Air
iata:
- LH
- EW
- DE
- X3
- HR
AE:
name:
- Emirates
- Etihad Airways
- Air Arabia
- flydubai
iata:
- EK
- EY
- G9
- FZ
QA:
name:
- Qatar Airways
iata:
- QR
JP:
name:
- Japan Airlines
- All Nippon Airways
- Peach Aviation
- Skymark Airlines
- Japan Air Commuter
- StarFlyer
- Fuji Dream Airlines
iata:
- JL
- NH
- MM
- BC
- JC
- 7G
- JH
AU:
name:
- Qantas
- Virgin Australia
- Jetstar Airways
- Rex Airlines
- Alliance Airlines
iata:
- QF
- VA
- JQ
- ZL
- QQ
SG:
name:
- Singapore Airlines
- Scoot
- Jetstar Asia Airways
iata:
- SQ
- TR
- 3K
29 changes: 29 additions & 0 deletions test/faker/travel/test_faker_airlines.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerAirline < Test::Unit::TestCase
def setup
@tester = Faker::Travel::Airline
end

def test_name
assert_match(/\w+/, @tester.name(country_code: 'US'))
end

def test_iata
assert_match(/\w+/, @tester.iata(country_code: 'US'))
end

def test_name_with_invalid_arguments
assert_raises ArgumentError do
@tester.name(cats: 'meow', dogs: 'woof')
end
end

def test_iata_with_invalid_arguments
assert_raises ArgumentError do
@tester.iata(cats: 'meow', dogs: 'woof')
end
end
end
Loading