Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add train station generator #2755

Merged
merged 11 commits into from
Jul 2, 2023
Merged
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"
AngusDSR marked this conversation as resolved.
Show resolved Hide resolved
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
48 changes: 48 additions & 0 deletions lib/faker/travel/train_station.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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)
regions = translate('faker.train_station').keys
types = translate('faker.train_station.united_kingdom').keys
AngusDSR marked this conversation as resolved.
Show resolved Hide resolved

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

fetch("train_station.#{region.downcase}.#{type.downcase}")
AngusDSR marked this conversation as resolved.
Show resolved Hide resolved
end

def validate_arguments(argument, correct_values, argument_name)
AngusDSR marked this conversation as resolved.
Show resolved Hide resolved
return if correct_values.include?(argument.downcase.to_sym)

raise ArgumentError, "'#{argument.downcase}' not found, #{argument_name} can be blank, or one of the following: #{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
Loading