From b56a41bd6eccf61e42764dde4a595a74bbaf1def Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Tue, 11 Apr 2023 20:04:18 +0100 Subject: [PATCH 01/10] UK metro and railway stations added + corrected a typo in airport.yml file '@retrun' => '@return' --- lib/faker/travel/airport.rb | 4 +- lib/faker/travel/train_station.rb | 26 ++++++ lib/locales/en/train_station.yml | 128 ++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 lib/faker/travel/train_station.rb create mode 100644 lib/locales/en/train_station.yml 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..baaea8d15a --- /dev/null +++ b/lib/faker/travel/train_station.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Faker + class Travel + class TrainStation < Base + class << self + ## + # Produces random Train Station by name and takes arguments for type, region + # + # @param type [String] Train station type: urban, national, international + # + # @param region [String] Train station region: united_kingdom, spain + # + # @return [String] + # + # @example + # Faker::Travel::TrainStation.name(type: 'urban', region: 'united_kingdom') => "Brockley" + # + # @faker.version next + def name(type:, region:) + fetch("train_station.#{type}.#{region}") + 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..aa35a1e728 --- /dev/null +++ b/lib/locales/en/train_station.yml @@ -0,0 +1,128 @@ +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 From 7cc9dd2d750858df84abe7081fd9b80a54e53b8a Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Tue, 11 Apr 2023 20:19:26 +0100 Subject: [PATCH 02/10] TrainStation test file added and.yml file structure corrected. Currently testing well for UK stations --- lib/faker/travel/train_station.rb | 4 ++-- lib/locales/en/train_station.yml | 7 ++++--- test/faker/travel/test_faker_train_station.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 test/faker/travel/test_faker_train_station.rb diff --git a/lib/faker/travel/train_station.rb b/lib/faker/travel/train_station.rb index baaea8d15a..09af948ba2 100644 --- a/lib/faker/travel/train_station.rb +++ b/lib/faker/travel/train_station.rb @@ -7,14 +7,14 @@ class << self ## # Produces random Train Station by name and takes arguments for type, region # - # @param type [String] Train station type: urban, national, international + # @param type [String] Train station type: metro, railway # # @param region [String] Train station region: united_kingdom, spain # # @return [String] # # @example - # Faker::Travel::TrainStation.name(type: 'urban', region: 'united_kingdom') => "Brockley" + # Faker::Travel::TrainStation.name(type: 'metro', region: 'united_kingdom') => "Brockley" # # @faker.version next def name(type:, region:) diff --git a/lib/locales/en/train_station.yml b/lib/locales/en/train_station.yml index aa35a1e728..5f066c7493 100644 --- a/lib/locales/en/train_station.yml +++ b/lib/locales/en/train_station.yml @@ -1,8 +1,8 @@ en: faker: train_station: - united_kingdom: - metro: + metro: + united_kingdom: - Aldgate - Aldgate East - Angel @@ -103,7 +103,8 @@ en: - West Jesmond - West Street - Westminster - railway: + railway: + united_kingdom: - Birmingham New Street railway station - Blackfriars station - Bristol Temple Meads railway 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..3af96be291 --- /dev/null +++ b/test/faker/travel/test_faker_train_station.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerTrainStation < Test::Unit::TestCase + def setup + @tester = Faker::Travel::TrainStation + end + + def test_name + assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_kingdom')) + end + + def test_name_with_invalid_arguments + assert_raises ArgumentError do + @tester.name(cats: 'meow', dogs: 'woof') + end + end +end From 50a544e82c9cfab51d15a3d4ef74030d5a47eece Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Tue, 11 Apr 2023 20:45:36 +0100 Subject: [PATCH 03/10] added Spanish trains and metro to .yml and tested --- lib/locales/en/train_station.yml | 58 +++++++++++++++++++ test/faker/travel/test_faker_train_station.rb | 6 +- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/lib/locales/en/train_station.yml b/lib/locales/en/train_station.yml index 5f066c7493..14b072a98a 100644 --- a/lib/locales/en/train_station.yml +++ b/lib/locales/en/train_station.yml @@ -103,6 +103,49 @@ en: - West Jesmond - West Street - Westminster + spain: + - Alto del Arenal + - Antiguas cocheras de Portazgo + - 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: united_kingdom: - Birmingham New Street railway station @@ -127,3 +170,18 @@ en: - Newcastle railway station - St Pancras railway station - York railway station + spain: + - 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 diff --git a/test/faker/travel/test_faker_train_station.rb b/test/faker/travel/test_faker_train_station.rb index 3af96be291..51a25e6e51 100644 --- a/test/faker/travel/test_faker_train_station.rb +++ b/test/faker/travel/test_faker_train_station.rb @@ -7,10 +7,14 @@ def setup @tester = Faker::Travel::TrainStation end - def test_name + def test_name_UK assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_kingdom')) end + def test_name_esp + assert_match(/\w+/, @tester.name(type: 'railway', region: 'spain')) + end + def test_name_with_invalid_arguments assert_raises ArgumentError do @tester.name(cats: 'meow', dogs: 'woof') From c34acc62178c1ce1e99483f555d1e2fb9a05ae6e Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Tue, 11 Apr 2023 21:07:05 +0100 Subject: [PATCH 04/10] German stations added and tested --- lib/locales/en/train_station.yml | 86 ++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/lib/locales/en/train_station.yml b/lib/locales/en/train_station.yml index 14b072a98a..9ee2b52d3b 100644 --- a/lib/locales/en/train_station.yml +++ b/lib/locales/en/train_station.yml @@ -105,7 +105,6 @@ en: - Westminster spain: - Alto del Arenal - - Antiguas cocheras de Portazgo - Antón Martín - Arco de Triunfo - Atocha @@ -146,6 +145,41 @@ en: - Universitat - Urgell - Urquinaona + germany: + - 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: united_kingdom: - Birmingham New Street railway station @@ -171,17 +205,39 @@ en: - St Pancras railway station - York railway station spain: - - 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 + - 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: + - 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 From 64f33ec50f00b9fd109d8f39facf9f997fe246dd Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Wed, 19 Apr 2023 18:02:11 +0100 Subject: [PATCH 05/10] US stations added and tested --- lib/locales/en/train_station.yml | 35 +++++++++++++++++++ test/faker/travel/test_faker_train_station.rb | 6 +++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/locales/en/train_station.yml b/lib/locales/en/train_station.yml index 9ee2b52d3b..33d7d2f41a 100644 --- a/lib/locales/en/train_station.yml +++ b/lib/locales/en/train_station.yml @@ -180,6 +180,27 @@ en: - Steinbühl - Tiergarten - Wittenbergplatz + united_states: + - 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: united_kingdom: - Birmingham New Street railway station @@ -241,3 +262,17 @@ en: - München Ost - Nürnberg Hauptbahnhof - Stuttgart Hauptbahnhof + united_states: + - 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 index 51a25e6e51..b4b0d542c9 100644 --- a/test/faker/travel/test_faker_train_station.rb +++ b/test/faker/travel/test_faker_train_station.rb @@ -7,7 +7,7 @@ def setup @tester = Faker::Travel::TrainStation end - def test_name_UK + def test_name_uk assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_kingdom')) end @@ -15,6 +15,10 @@ def test_name_esp assert_match(/\w+/, @tester.name(type: 'railway', region: 'spain')) end + def test_name_us + assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_states')) + end + def test_name_with_invalid_arguments assert_raises ArgumentError do @tester.name(cats: 'meow', dogs: 'woof') From 9123c14bd5343a888073c586e8ab26286cf9782f Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Sat, 17 Jun 2023 16:15:46 +0100 Subject: [PATCH 06/10] Made both parameters for #name optional / validation & refactor / updated main README.md and set up train_station.md in docs --- README.md | 1 + doc/travel/train_station.md | 7 ++++ lib/faker/travel/train_station.rb | 32 ++++++++++++++++--- test/faker/travel/test_faker_train_station.rb | 10 +++++- 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 doc/travel/train_station.md diff --git a/README.md b/README.md index c97d8cfaaf..6571235f27 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..c846d178b0 --- /dev/null +++ b/doc/travel/train_station.md @@ -0,0 +1,7 @@ +# Faker::Travel::TrainStation + +```ruby +Faker::Travel::TrainStation.name(type: 'metro', region: 'united_kingdom') #=> "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/train_station.rb b/lib/faker/travel/train_station.rb index 09af948ba2..2d084145af 100644 --- a/lib/faker/travel/train_station.rb +++ b/lib/faker/travel/train_station.rb @@ -5,20 +5,42 @@ class Travel class TrainStation < Base class << self ## - # Produces random Train Station by name and takes arguments for type, region + # Produces random Train Station by name and takes optional arguments for type and region # # @param type [String] Train station type: metro, railway # - # @param region [String] Train station region: united_kingdom, spain + # @param region [String] Train station region: germany, spain, united_kingdom, united_states # # @return [String] # - # @example + # @examples # Faker::Travel::TrainStation.name(type: 'metro', region: 'united_kingdom') => "Brockley" + # Faker::Travel::TrainStation.name(type: 'railway') => "Düsseldorf Hauptbahnhof" + # Faker::Travel::TrainStation.name(region: 'spain') => "Santa Eulàlia" # # @faker.version next - def name(type:, region:) - fetch("train_station.#{type}.#{region}") + def name(type: nil, region: nil) + types = translate('faker.train_station').keys + regions = translate('faker.train_station.metro').keys + + if type.nil? && region.nil? + type = sample(types) + region = sample(regions) + elsif type.nil? + validate_arguments(region, regions) + type = sample(types) + elsif region.nil? + validate_arguments(type, types) + region = sample(regions) + end + + fetch("train_station.#{type.to_s.downcase}.#{region.to_s.downcase}") + end + + def validate_arguments(argument, correct_values) + return if correct_values.include?(argument.to_sym) + + raise ArgumentError, "#{argument} can be blank, or one of the following #{correct_values.join(', ')}" end end end diff --git a/test/faker/travel/test_faker_train_station.rb b/test/faker/travel/test_faker_train_station.rb index b4b0d542c9..e5e280de64 100644 --- a/test/faker/travel/test_faker_train_station.rb +++ b/test/faker/travel/test_faker_train_station.rb @@ -19,9 +19,17 @@ def test_name_us assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_states')) end + def test_name_no_args + assert_match(/\w+/, @tester.name) + end + + # test for region only + + # test for type only + def test_name_with_invalid_arguments assert_raises ArgumentError do - @tester.name(cats: 'meow', dogs: 'woof') + @tester.name(bee: 'bzzz', fish: 'blub') end end end From ea570b0e5d7772198cd7e02e67cedc8eb7b51b59 Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Sat, 17 Jun 2023 17:02:31 +0100 Subject: [PATCH 07/10] additional tests added for optional arguments / allowance for case-insensitivity added / refactored --- lib/faker/travel/train_station.rb | 12 ++++++------ test/faker/travel/test_faker_train_station.rb | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/faker/travel/train_station.rb b/lib/faker/travel/train_station.rb index 2d084145af..50096070b4 100644 --- a/lib/faker/travel/train_station.rb +++ b/lib/faker/travel/train_station.rb @@ -27,20 +27,20 @@ def name(type: nil, region: nil) type = sample(types) region = sample(regions) elsif type.nil? - validate_arguments(region, regions) + validate_arguments(region, regions, 'region') type = sample(types) elsif region.nil? - validate_arguments(type, types) + validate_arguments(type, types, 'type') region = sample(regions) end - fetch("train_station.#{type.to_s.downcase}.#{region.to_s.downcase}") + fetch("train_station.#{type.downcase}.#{region.downcase}") end - def validate_arguments(argument, correct_values) - return if correct_values.include?(argument.to_sym) + def validate_arguments(argument, correct_values, argument_name) + return if correct_values.include?(argument.downcase.to_sym) - raise ArgumentError, "#{argument} can be blank, or one of the following #{correct_values.join(', ')}" + raise ArgumentError, "'#{argument.downcase}' not found, #{argument_name} can be blank, or one of the following: #{correct_values.join(', ')}" end end end diff --git a/test/faker/travel/test_faker_train_station.rb b/test/faker/travel/test_faker_train_station.rb index e5e280de64..795acb9aad 100644 --- a/test/faker/travel/test_faker_train_station.rb +++ b/test/faker/travel/test_faker_train_station.rb @@ -9,6 +9,9 @@ def setup def test_name_uk assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_kingdom')) + assert_match(/\w+/, @tester.name(type: 'metro', region: 'United_Kingdom')) + assert_match(/\w+/, @tester.name(type: 'metro', region: :united_kingdom)) + assert_match(/\w+/, @tester.name(type: 'metro', region: :United_Kingdom)) end def test_name_esp @@ -23,9 +26,17 @@ def test_name_no_args assert_match(/\w+/, @tester.name) end - # test for region only + def test_region_only + assert_match(/\w+/, @tester.name(region: 'germany')) + assert_match(/\w+/, @tester.name(region: 'Germany')) + assert_match(/\w+/, @tester.name(region: :Germany)) + end - # test for type only + def test_type_only + assert_match(/\w+/, @tester.name(type: :metro)) + assert_match(/\w+/, @tester.name(type: :railway)) + assert_match(/\w+/, @tester.name(type: 'railway')) + end def test_name_with_invalid_arguments assert_raises ArgumentError do From 1bde0994d557d7a768b6425129e0a27c399c85dd Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Sat, 17 Jun 2023 17:19:11 +0100 Subject: [PATCH 08/10] changed the order of the params for #name: updated the .yml and the docs and restructured the code to correspond --- doc/travel/train_station.md | 2 +- lib/faker/travel/train_station.rb | 24 +- lib/locales/en/train_station.yml | 550 +++++++++--------- test/faker/travel/test_faker_train_station.rb | 12 +- 4 files changed, 295 insertions(+), 293 deletions(-) diff --git a/doc/travel/train_station.md b/doc/travel/train_station.md index c846d178b0..8267290abe 100644 --- a/doc/travel/train_station.md +++ b/doc/travel/train_station.md @@ -1,7 +1,7 @@ # Faker::Travel::TrainStation ```ruby -Faker::Travel::TrainStation.name(type: 'metro', region: 'united_kingdom') #=> "Brockley" +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/train_station.rb b/lib/faker/travel/train_station.rb index 50096070b4..544bb214ef 100644 --- a/lib/faker/travel/train_station.rb +++ b/lib/faker/travel/train_station.rb @@ -5,36 +5,36 @@ class Travel class TrainStation < Base class << self ## - # Produces random Train Station by name and takes optional arguments for type and region - # - # @param type [String] Train station type: metro, railway + # 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(type: 'metro', region: 'united_kingdom') => "Brockley" + # 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(type: nil, region: nil) - types = translate('faker.train_station').keys - regions = translate('faker.train_station.metro').keys + def name(region: nil, type: nil) + regions = translate('faker.train_station').keys + types = translate('faker.train_station.united_kingdom').keys - if type.nil? && region.nil? - type = sample(types) + if region.nil? && type.nil? region = sample(regions) - elsif type.nil? - validate_arguments(region, regions, 'region') 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.#{type.downcase}.#{region.downcase}") + fetch("train_station.#{region.downcase}.#{type.downcase}") end def validate_arguments(argument, correct_values, argument_name) diff --git a/lib/locales/en/train_station.yml b/lib/locales/en/train_station.yml index 33d7d2f41a..fd3696d609 100644 --- a/lib/locales/en/train_station.yml +++ b/lib/locales/en/train_station.yml @@ -1,278 +1,280 @@ en: faker: - train_station: + train_station: + united_kingdom: metro: - united_kingdom: - - 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 - spain: - - 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 - germany: - - 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 - united_states: - - 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 + - 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: - united_kingdom: - - 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: - - 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: - - 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: - - 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 + - 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 index 795acb9aad..b6cdf1a99e 100644 --- a/test/faker/travel/test_faker_train_station.rb +++ b/test/faker/travel/test_faker_train_station.rb @@ -8,18 +8,18 @@ def setup end def test_name_uk - assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_kingdom')) - assert_match(/\w+/, @tester.name(type: 'metro', region: 'United_Kingdom')) - assert_match(/\w+/, @tester.name(type: 'metro', region: :united_kingdom)) - assert_match(/\w+/, @tester.name(type: 'metro', region: :United_Kingdom)) + assert_match(/\w+/, @tester.name(region: 'united_kingdom', type: 'metro')) + assert_match(/\w+/, @tester.name(region: 'United_Kingdom', type: 'metro')) + 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(type: 'railway', region: 'spain')) + assert_match(/\w+/, @tester.name(region: 'spain', type: 'railway')) end def test_name_us - assert_match(/\w+/, @tester.name(type: 'metro', region: 'united_states')) + assert_match(/\w+/, @tester.name(region: 'united_states', type: 'metro')) end def test_name_no_args From 1db85284b211ec289872e37447eb6239c2145cb5 Mon Sep 17 00:00:00 2001 From: Angus Spawton-Rice Date: Sat, 24 Jun 2023 13:03:30 +0100 Subject: [PATCH 09/10] removed downcasing and symbol compatibility // created #fill_missing_inputs_with_samples method and moved into private with #validate_arguments --- doc/travel/train_station.md | 2 +- lib/faker/travel/train_station.rb | 19 +++++++++++++------ test/faker/travel/test_faker_train_station.rb | 8 ++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/doc/travel/train_station.md b/doc/travel/train_station.md index 8267290abe..45426a72a4 100644 --- a/doc/travel/train_station.md +++ b/doc/travel/train_station.md @@ -1,7 +1,7 @@ # Faker::Travel::TrainStation ```ruby -Faker::Travel::TrainStation.name(region: 'united_kingdom',type: 'metro') #=> "Brockley" +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/train_station.rb b/lib/faker/travel/train_station.rb index 544bb214ef..a4362a244f 100644 --- a/lib/faker/travel/train_station.rb +++ b/lib/faker/travel/train_station.rb @@ -20,8 +20,15 @@ class << self # # @faker.version next def name(region: nil, type: nil) - regions = translate('faker.train_station').keys - types = translate('faker.train_station.united_kingdom').keys + 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) @@ -33,15 +40,15 @@ def name(region: nil, type: nil) validate_arguments(region, regions, 'region') type = sample(types) end - - fetch("train_station.#{region.downcase}.#{type.downcase}") + [region, type] end def validate_arguments(argument, correct_values, argument_name) - return if correct_values.include?(argument.downcase.to_sym) + return if correct_values.include?(argument) - raise ArgumentError, "'#{argument.downcase}' not found, #{argument_name} can be blank, or one of the following: #{correct_values.join(', ')}" + raise ArgumentError, "'#{argument}' not found, #{argument_name} can be blank, or one of the following, as strings: #{correct_values.join(', ')}" end + end end end diff --git a/test/faker/travel/test_faker_train_station.rb b/test/faker/travel/test_faker_train_station.rb index b6cdf1a99e..30ef974352 100644 --- a/test/faker/travel/test_faker_train_station.rb +++ b/test/faker/travel/test_faker_train_station.rb @@ -9,9 +9,7 @@ def setup def test_name_uk assert_match(/\w+/, @tester.name(region: 'united_kingdom', type: 'metro')) - assert_match(/\w+/, @tester.name(region: 'United_Kingdom', type: 'metro')) 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 @@ -28,13 +26,11 @@ def test_name_no_args def test_region_only assert_match(/\w+/, @tester.name(region: 'germany')) - assert_match(/\w+/, @tester.name(region: 'Germany')) - 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)) + assert_match(/\w+/, @tester.name(type: 'metro')) assert_match(/\w+/, @tester.name(type: 'railway')) end From dfd18a1e20e1962b959b2b0efcdb285ac0d54732 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Sat, 1 Jul 2023 19:12:57 -0600 Subject: [PATCH 10/10] remove extra line --- lib/faker/travel/train_station.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/faker/travel/train_station.rb b/lib/faker/travel/train_station.rb index a4362a244f..6ca02153fc 100644 --- a/lib/faker/travel/train_station.rb +++ b/lib/faker/travel/train_station.rb @@ -48,7 +48,6 @@ def validate_arguments(argument, correct_values, argument_name) raise ArgumentError, "'#{argument}' not found, #{argument_name} can be blank, or one of the following, as strings: #{correct_values.join(', ')}" end - end end end