Skip to content

Commit

Permalink
added travel folder and airports (#2601)
Browse files Browse the repository at this point in the history
* 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 <stefannibrasil@gmail.com>

* Update lib/faker/travel/airport.rb

Co-authored-by: Thiago Araujo <thd.araujo@gmail.com>

* Update lib/faker/travel/airport.rb

Co-authored-by: Thiago Araujo <thd.araujo@gmail.com>

* 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 <stefannibrasil@gmail.com>
Co-authored-by: Thiago Araujo <thd.araujo@gmail.com>
  • Loading branch information
3 people committed Nov 8, 2022
1 parent 05a5e1e commit 25d45f6
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions doc/travel/airport.md
Original file line number Diff line number Diff line change
@@ -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"
```
47 changes: 47 additions & 0 deletions lib/faker/travel/airport.rb
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 25d45f6

Please sign in to comment.