diff --git a/README.md b/README.md index 679c22aba8..2bb0ab7dae 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main Travel - [Faker:Travel::Airport](doc/travel/airport.md) + - [Faker:Travel::TrainStation](doc/travel/train_station.md)
diff --git a/doc/travel/train_station.md b/doc/travel/train_station.md new file mode 100644 index 0000000000..45426a72a4 --- /dev/null +++ b/doc/travel/train_station.md @@ -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" +``` diff --git a/lib/faker/travel/airport.rb b/lib/faker/travel/airport.rb index c28df9139f..8d08759168 100644 --- a/lib/faker/travel/airport.rb +++ b/lib/faker/travel/airport.rb @@ -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" @@ -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" diff --git a/lib/faker/travel/train_station.rb b/lib/faker/travel/train_station.rb new file mode 100644 index 0000000000..6ca02153fc --- /dev/null +++ b/lib/faker/travel/train_station.rb @@ -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 diff --git a/lib/locales/en/train_station.yml b/lib/locales/en/train_station.yml new file mode 100644 index 0000000000..fd3696d609 --- /dev/null +++ b/lib/locales/en/train_station.yml @@ -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 diff --git a/test/faker/travel/test_faker_train_station.rb b/test/faker/travel/test_faker_train_station.rb new file mode 100644 index 0000000000..30ef974352 --- /dev/null +++ b/test/faker/travel/test_faker_train_station.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerTrainStation < Test::Unit::TestCase + def setup + @tester = Faker::Travel::TrainStation + end + + def test_name_uk + assert_match(/\w+/, @tester.name(region: 'united_kingdom', type: 'metro')) + assert_match(/\w+/, @tester.name(region: :united_kingdom, type: 'metro')) + end + + def test_name_esp + assert_match(/\w+/, @tester.name(region: 'spain', type: 'railway')) + end + + def test_name_us + assert_match(/\w+/, @tester.name(region: 'united_states', type: 'metro')) + end + + def test_name_no_args + assert_match(/\w+/, @tester.name) + end + + def test_region_only + assert_match(/\w+/, @tester.name(region: 'germany')) + assert_match(/\w+/, @tester.name(region: 'united_states')) + end + + def test_type_only + assert_match(/\w+/, @tester.name(type: 'metro')) + assert_match(/\w+/, @tester.name(type: 'railway')) + end + + def test_name_with_invalid_arguments + assert_raises ArgumentError do + @tester.name(bee: 'bzzz', fish: 'blub') + end + end +end