Skip to content

Commit

Permalink
Add train station generator (#2755)
Browse files Browse the repository at this point in the history
* UK metro and railway stations added + corrected a typo in airport.yml file '@retrun' => '@return'

* TrainStation test file added and.yml file structure corrected. Currently testing well for UK stations

* added Spanish trains and metro to .yml and tested

* German stations added and tested

* US stations added and tested

* Made both parameters for #name optional / validation & refactor / updated main README.md and set up train_station.md in docs

* additional tests added for optional arguments / allowance for case-insensitivity added / refactored

* changed the order of the params for #name: updated the .yml and the docs and restructured the code to correspond

* removed downcasing and symbol compatibility // created #fill_missing_inputs_with_samples method and moved into private with #validate_arguments
  • Loading branch information
AngusDSR committed Jul 2, 2023
1 parent a9620b2 commit a342e3e
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,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::TrainStation](doc/travel/train_station.md)
</details>

<details>
Expand Down
7 changes: 7 additions & 0 deletions doc/travel/train_station.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Faker::Travel::TrainStation

```ruby
Faker::Travel::TrainStation.name(region: 'united_kingdom', type: 'metro') #=> "Brockley"
Faker::Travel::TrainStation.name(type: 'railway') #=> "Düsseldorf Hauptbahnhof"
Faker::Travel::TrainStation.name(region: 'spain') #=> "Santa Eulàlia"
```
4 changes: 2 additions & 2 deletions lib/faker/travel/airport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class << self
#
# @param region [String] airport region, currently available -> united_states or european_union
#
# @retrun [String]
# @return [String]
#
# @example
# Faker::Travel::Airport.name(size: 'large', region: 'united_states') => "Los Angeles International Airport"
Expand All @@ -28,7 +28,7 @@ def name(size:, region:)
#
# @param region [String] airport region, currently available -> united_states or european_union
#
# @retrun [String]
# @return [String]
#
# @example
# Faker::Travel::Airport.iata(size: 'large', region: 'united_states') => "LAX"
Expand Down
54 changes: 54 additions & 0 deletions lib/faker/travel/train_station.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

module Faker
class Travel
class TrainStation < Base
class << self
##
# Produces random Train Station by name and takes optional arguments for region and type
#
# @param region [String] Train station region: germany, spain, united_kingdom, united_states
#
# @param type [String] Train station type: metro, railway
#
# @return [String]
#
# @examples
# Faker::Travel::TrainStation.name(region: 'united_kingdom', type: 'metro') => "Brockley"
# Faker::Travel::TrainStation.name(type: 'railway') => "Düsseldorf Hauptbahnhof"
# Faker::Travel::TrainStation.name(region: 'spain') => "Santa Eulàlia"
#
# @faker.version next
def name(region: nil, type: nil)
region, type = fill_missing_inputs_with_samples(region, type)
fetch("train_station.#{region}.#{type}")
end

private

def fill_missing_inputs_with_samples(region, type)
regions = %w[germany spain united_kingdom united_states]
types = %w[metro railway]

if region.nil? && type.nil?
region = sample(regions)
type = sample(types)
elsif region.nil?
validate_arguments(type, types, 'type')
region = sample(regions)
elsif type.nil?
validate_arguments(region, regions, 'region')
type = sample(types)
end
[region, type]
end

def validate_arguments(argument, correct_values, argument_name)
return if correct_values.include?(argument)

raise ArgumentError, "'#{argument}' not found, #{argument_name} can be blank, or one of the following, as strings: #{correct_values.join(', ')}"
end
end
end
end
end
280 changes: 280 additions & 0 deletions lib/locales/en/train_station.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
en:
faker:
train_station:
united_kingdom:
metro:
- Aldgate
- Aldgate East
- Angel
- Baker Street
- Bank
- Barbican
- Battersea Power Station
- Bayswater
- Blackfriars
- Bond Street
- Borough
- Bridge Street
- Brockley
- Buchanan Street
- Byker
- Cannon Street
- Central Station
- Cessnock
- Chancery Lane
- Charing Cross
- Chillingham Road
- City Thameslink
- Covent Garden
- Cowcaddens
- Earl's Court
- Edgware Road
- Elephant & Castle
- Embankment
- Euston
- Euston Square
- Farringdon
- Fenchurch Street
- Gateshead
- Gateshead Stadium
- Gloucester Road
- Goodge Street
- Govan
- Great Portland Street
- Green Park
- Haymarket
- High Street Kensington
- Hillhead
- Holborn
- Hoxton
- Hyde Park Corner
- Ibrox
- Ilford Road
- Jesmond
- Kelvinbridge
- Kelvinhall
- Kennington
- King's Cross St Pancras
- Kinning Park
- Knightsbridge
- Lambeth North
- Lancaster Gate
- Leicester Square
- Liverpool Street
- London Bridge
- Manors
- Mansion House
- Marble Arch
- Marylebone
- Monument
- Moorgate
- Nine Elms
- Notting Hill Gate
- Old Street
- Oxford Circus
- Paddington
- Patrick
- Piccadilly Circus
- Pimlico
- Queensway
- Regent's Park
- River Tyne
- Russell Square
- Shields Road
- Shoreditch High Street
- Sloane Square
- South Kensington
- Southwark
- St Enoch
- St George's Cross
- St James
- St James's Park
- St Paul's
- Temple
- Tottenham Court Road
- Tower Gateway
- Tower Hill
- Vauxhall
- Victoria
- Walkergate
- Warren Street
- Waterloo
- Waterloo East
- West Jesmond
- West Street
- Westminster
railway:
- Birmingham New Street railway station
- Blackfriars station
- Bristol Temple Meads railway station
- Cannon Street station
- Cardiff Central railway station
- Charing Cross railway station
- Coventry railway station
- Euston railway station
- Fenchurch Street railway station
- Leeds railway station
- Liverpool Lime Street railway station
- Liverpool Street station
- London Bridge station
- London King's Cross railway station
- London Paddington station
- London Victoria station
- London Waterloo station
- Manchester Piccadilly station
- Marylebone station
- Newcastle railway station
- St Pancras railway station
- York railway station
spain:
metro:
- Alto del Arenal
- Antón Martín
- Arco de Triunfo
- Atocha
- Bellvitge Rambla Marina
- Bilbao
- Buenos Aires
- El Clot
- Estación del Arte
- Glòries
- Gran Vía
- Hospital de Bellvitge
- Hostafrancs
- Iglesia
- La Sagrera
- Marina
- Menéndez Pelayo
- Miguel Hernández
- Monumental
- Nueva Numancia
- Pacífico
- Plaça de Sants
- Plaza de Cataluña
- Plaza España
- Poble Sec
- Portazgo
- Puente de Vallecas
- Puerta del Sol
- Ríos Rosas
- Rocafort
- Sagrada Família
- Sant Andreu
- Santa Coloma
- Santa Eulàlia
- Sol
- Tirso de Molina
- Torrassa
- Tribunal
- Universitat
- Urgell
- Urquinaona
railway:
- Madrid Atocha
- Barcelona Sants
- Seville-Santa Justa
- Zaragoza–Delicias
- Madrid Chamartín
- Valencia-Joaquín Sorolla
- Málaga-María Zambrano
- Granada
- Alicante Terminal
- Valladolid-Campo Grande
- A Coruña-San Cristóbal
- Santiago de Compostela railway station
- Ourense
- Córdoba
germany:
metro:
- Alexanderplatz
- Aufseßplatz
- Bismarckstraße
- Bülowstraße
- Central Station
- Gleisdreieck
- Görlitzer Bahnhof
- Hallesches Tor
- Hauptbahnhof
- Hausvogteiplatz
- Kaiserdamm
- Klosterstraße
- Kolumbusplatz
- Kottbusser Tor
- Kurfürstenstraße
- Märkisches Museum
- Mendelssohn-Bartholdy-Park
- Möckernbrücke
- Mohrenstraße
- Nollendorfplatz
- Potsdamer Platz
- Prinzenstraße
- Rathenauplatz
- Rosa-Luxemburg-Platz
- Rotkreuzplatz
- Scheidplatz
- Sendlinger Tor
- Senefelderplatz
- Spittelmarkt
- St. Johannis
- Stadtmitte
- Steinbühl
- Tiergarten
- Wittenbergplatz
railway:
- Berlin-Gesundbrunnen station
- Berlin Hauptbahnhof
- Berlin Ostbahnhof
- Berlin Südkreuz
- Dortmund Hauptbahnhof
- Dresden Hauptbahnhof
- Duisburg Hauptbahnhof
- Düsseldorf Hauptbahnhof
- Essen Hauptbahnhof
- Frankfurt Hauptbahnhof
- Hamburg-Altona station
- Hamburg Hauptbahnhof
- Hannover Hauptbahnhof
- Karlsruhe Hauptbahnhof
- Köln Hauptbahnhof
- Köln Messe/Deutz station
- Leipzig Hauptbahnhof
- München Hauptbahnhof
- München Ost
- Nürnberg Hauptbahnhof
- Stuttgart Hauptbahnhof
united_states:
metro:
- Back Bay
- Belmont
- Braintree
- Downtown Crossing
- Forest Hills
- Haymarket
- Jefferson Park
- Kimball
- Malden Center
- North Hollywood
- North Station
- Park Street
- Quincy Center
- Redondo Beach
- Rosemont
- Ruggles
- South Station
- The Loop
- Union Station
- Wonderland
railway:
- 30th Street Station
- Chicago Union Station
- Grand Central Terminal
- Hoboken Terminal
- Jamaica Station
- Los Angeles Union Station
- Millennium Station
- New York Penn Station
- Newark Penn Station
- Ogilvie Transportation Center
- Secaucus Junction
- South Station
- Washington Union Station
Loading

0 comments on commit a342e3e

Please sign in to comment.