diff --git a/doc/tv_shows/stargate.md b/doc/tv_shows/stargate.md index a9a43fdb01..854367389d 100644 --- a/doc/tv_shows/stargate.md +++ b/doc/tv_shows/stargate.md @@ -1,9 +1,9 @@ # Faker::TvShows::Stargate ```ruby -Faker::TvShows::StarTrek.character #=> "Jack O'Neill" +Faker::TvShows::Stargate.character #=> "Jack O'Neill" -Faker::TvShows::StarTrek.planet #=> "Abydos" +Faker::TvShows::Stargate.planet #=> "Abydos" -Faker::TvShows::StarTrek.quote #=> "General, request permission to beat the crap out of this man." +Faker::TvShows::Stargate.quote #=> "General, request permission to beat the crap out of this man." ``` diff --git a/doc/unreleased/default/internet.md b/doc/unreleased/default/internet.md index 2621e5745f..1af415e2bc 100644 --- a/doc/unreleased/default/internet.md +++ b/doc/unreleased/default/internet.md @@ -79,4 +79,6 @@ Faker::Internet.slug('foo bar', '-') #=> "foo-bar" # Optional argument: vendor=nil Faker::Internet.user_agent #=> "Mozilla/5.0 (compatible; MSIE 9.0; AOL 9.7; AOLBuild 4343.19; Windows NT 6.1; WOW64; Trident/5.0; FunWebProducts)" Faker::Internet.user_agent(:firefox) #=> "Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0" + +Faker::Internet.uuid #=> "929ef6ef-b11f-38c9-111b-accd67a258b2" ``` diff --git a/doc/unreleased/games/game.md b/doc/unreleased/games/game.md new file mode 100644 index 0000000000..c16a0188ce --- /dev/null +++ b/doc/unreleased/games/game.md @@ -0,0 +1,12 @@ +# Faker::Game + +```ruby +# Random Game Title +Faker::Game.title #=> "Half-Life" + +# Random Game Genre +Faker::Game.genre #=> "First-person shooter" + +# Random Game Platform +Faker::Game.platform #=> "Nintendo DS" +``` diff --git a/lib/faker/default/internet.rb b/lib/faker/default/internet.rb index 9bbdb79a97..09447f67fa 100644 --- a/lib/faker/default/internet.rb +++ b/lib/faker/default/internet.rb @@ -192,6 +192,14 @@ def user_agent(vendor = nil) sample(agents) end + def uuid + # borrowed from: https://github.com/ruby/ruby/blob/d48783bb0236db505fe1205d1d9822309de53a36/lib/securerandom.rb#L250 + ary = Faker::Config.random.bytes(16).unpack('NnnnnN') + ary[2] = (ary[2] & 0x0fff) | 0x4000 + ary[3] = (ary[3] & 0x3fff) | 0x8000 + '%08x-%04x-%04x-%04x-%04x%08x' % ary # rubocop:disable Style/FormatString + end + alias user_name username end end diff --git a/lib/faker/default/json.rb b/lib/faker/default/json.rb index d47df8a429..98fca34e71 100644 --- a/lib/faker/default/json.rb +++ b/lib/faker/default/json.rb @@ -4,16 +4,16 @@ class Json < Base class << self def shallow_json(width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' }) - options[:key] = options[:key].prepend('Faker::') - options[:value] = options[:value].prepend('Faker::') + options[:key] = 'Faker::' + options[:key] + options[:value] = 'Faker::' + options[:value] hash = build_shallow_hash(width, options) JSON.generate(hash) end def add_depth_to_json(json = shallow_json, width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' }) - options[:key] = options[:key].prepend('Faker::') - options[:value] = options[:value].prepend('Faker::') + options[:key] = 'Faker::' + options[:key] + options[:value] = 'Faker::' + options[:value] hash = JSON.parse(json) hash.each do |key, _| diff --git a/lib/faker/games/game.rb b/lib/faker/games/game.rb new file mode 100644 index 0000000000..12cd9c1e0d --- /dev/null +++ b/lib/faker/games/game.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Faker + class Game < Base + flexible :game + + class << self + def title + fetch('game.title') + end + + def genre + fetch('game.genre') + end + + def platform + fetch('game.platform') + end + end + end +end diff --git a/lib/locales/en/game.yml b/lib/locales/en/game.yml new file mode 100644 index 0000000000..defe7bba8f --- /dev/null +++ b/lib/locales/en/game.yml @@ -0,0 +1,251 @@ +en: + faker: + game: + title: + - 'Half-Life' + - 'Half-Life: Opposing Force' + - 'Half-Life: Blue Shift' + - 'Half-Life 2' + - 'Half-Life 2: Episode One' + - 'Half-Life 2: Episode Two' + - 'Half-Life 2: Lost Coast' + - 'Portal' + - 'Portal 2' + - 'Team Fortress Classic' + - 'Team Fortress 2' + - 'Left 4 Dead' + - 'Left 4 Dead 2' + - 'Day of Defeat' + - 'Ricochet' + - 'Dota 2' + - 'Counter-Strike' + - 'Counter-Strike: Source' + - 'Counter-Strike: Global Offensive' + - "Garry's Mod" + - 'Super Mario Bros.' + - 'Super Mario Bros. 2' + - 'Super Mario Bros. 3' + - 'Super Mario World' + - 'Super Mario Sunshine' + - 'Super Mario Galaxy' + - 'Super Mario Galaxy 2' + - 'Super Mario Odyssey' + - 'Mario Kart 64' + - 'Mario Kart: Double Dash' + - 'Mario Kart DS' + - 'Mario Kart Wii' + - 'Mario Kart 7' + - 'Mario Kart 8' + - 'Mario Kart 8 Deluxe' + - "Luigi's Mansion" + - 'Animal Crossing' + - 'Animal Crossing: Wild World' + - 'Animal Crossing: City Folk' + - 'Animal Crossing: New Leaf' + - 'Civilization III' + - 'Civilization IV' + - 'Civilization V' + - 'Civilization VI' + - 'The Legend of Zelda' + - 'The Legend of Zelda: Ocarina of Time' + - "The Legend of Zelda: Majora's Mask" + - 'The Legend of Zelda: Twilight Princess' + - 'The Legend of Zelda: Skyward Sword' + - 'The Legend of Zelda: Breath of the Wild' + - 'Pong' + - 'Pac-Man' + - 'Starcraft' + - 'Starcraft II' + - 'Overwatch' + - 'Hearthstone' + - 'Halo: Combat Evolved' + - 'Halo 2' + - 'Halo 3' + - 'Halo 3: ODST' + - 'Halo: Reach' + - 'Halo 4' + - 'Halo 5: Guardians' + - 'Wii Sports' + - 'Wii Sports Resort' + - 'Wii Play' + - 'Wii Music' + - 'Pokémon Red' + - 'Pokémon Blue' + - 'Pokémon Yellow' + - 'Pokémon Gold' + - 'Pokémon Silver' + - 'Pokémon Crystal' + - 'Pokémon Ruby' + - 'Pokémon Sapphire' + - 'Pokémon FireRed' + - 'Pokémon LeafGreen' + - 'Pokémon Emerald' + - 'Pokémon Diamond' + - 'Pokémon Pearl' + - 'Pokémon Platinum' + - 'Pokémon HeartGold' + - 'Pokémon SoulSilver' + - 'Pokémon Black' + - 'Pokémon White' + - 'Pokémon Black 2' + - 'Pokémon White 2' + - 'Pokémon X' + - 'Pokémon Y' + - 'Pokémon Omega Ruby' + - 'Pokémon Alpha Sapphire' + - 'Pokémon Sun' + - 'Pokémon Moon' + - 'Pokémon Ultra Sun' + - 'Pokémon Ultra Moon' + - "Pokémon: Let's Go Pikachu!" + - "Pokémon: Let's Go Eevee!" + - 'Pokémon Sword' + - 'Pokémon Shield' + - 'Doom' + - 'Doom II' + - 'Doom 3: BFG' + - 'Quake' + - 'Wolfenstein 3D' + - 'Wolfenstein: The New Order' + - 'Wolfenstein: The Old Blood' + - 'Wolfenstein 2: The New Colossus' + - 'Puyo Puyo Tetris' + - 'Katamari Damacy' + - 'Bastion' + - 'Transistor' + - 'System Shock' + - 'BioShock' + - 'BioShock Infinite' + - 'Deus Ex' + - 'Metroid Prime' + - 'Metroid Prime 2: Echoes' + - 'Metroid Prime 3: Corruption' + - 'Super Meat Boy' + - 'Super Smash Bros. Brawl' + - 'Super Smash Bros. Melee' + - 'Super Smash Bros. Ultimate' + - 'Thief II' + - 'Vampire: The Masquerade – Bloodlines' + - 'Myst' + - 'Batman: Arkham Asylum' + - 'Batman: Arkham City' + - 'Dishonored' + - 'God of War' + - 'LittleBigPlanet' + - 'Grim Fandango' + - 'Day of the Tentacle' + - 'Kingdom Hearts' + - 'Kingdom Hearts II' + - 'The Last of Us' + - 'Perfect Dark' + - 'Shadow of the Colossus' + - 'Fallout: New Vegas' + - 'Fire Emblem Awakening' + - "Banjo-Kazooie: Grunty's Revenge" + - 'Banjo-Kazooie: Nuts & Bolts' + - 'Firewatch' + - 'Mass Effect' + - 'Mass Effect 2' + - 'Mass Effect 3' + - 'Mega Man' + - 'Mega Man Battle Network' + - 'Bayonetta' + - 'Bayonetta 2' + - 'The Wonderful 101' + - 'Sleeping Dogs' + - 'Battletoads' + - 'Brütal Legend' + - 'Halo Wars' + - 'Clannad' + - 'Highway Blossoms' + - 'Infamous' + - 'Crash Bandicoot' + - 'Just Cause' + - 'Just Cause 2' + - 'Devil May Cry' + - 'Life is Strange' + - 'WarioWare: Smooth Moves' + - 'WarioWare: Touched!' + - 'Dwarf Fortress' + - 'Dungeon Keeper' + - 'Minecraft' + - 'Fortnite' + - "PlayerUnknown's Battlegrounds" + - "Kirby's Adventure" + - "Kirby's Dream Land" + - "Kirby's Epic Yarn" + - "Yoshi's Wooly World" + - 'L.A. Noire' + - 'Kid Icarus' + - 'Ice Climbers' + - 'Crysis' + - 'Crysis 2' + - 'Hitman: Absolution' + - 'Metal Gear Solid' + - 'F-Zero' + - 'F.E.A.R.' + - 'Max Payne' + - 'Max Payne 2: The Fall of Max Payne' + - 'Max Payne 3' + - 'Far Cry' + - 'Castle Crashers' + - 'Sonic Unleashed' + - "Mirror's Edge" + - 'The Witcher' + - 'The Witcher 2: Assassins of Kings' + - 'The Witcher 3: Wild Hunt' + - 'Monster Hunter: World' + genre: + - 'First-person shooter' + - 'Puzzle' + - 'Platformer' + - 'Action' + - 'Adventure' + - 'Strategy' + - 'Role-playing game' + - 'Sports' + - 'Simulation' + - 'Fighting' + - 'Massively multiplayer online' + - 'Stealth' + - 'Survival' + - 'Rhythm' + - 'Survival horror' + - 'Text adventure' + - 'Visual novel' + - 'Real-time strategy' + - 'Multiplayer online battle arena' + - 'Tower defense' + - 'Trivia' + platform: + - 'Xbox' + - 'Xbox 360' + - 'Xbox One' + - 'PlayStation' + - 'PlayStation 2' + - 'PlayStation 3' + - 'PlayStation 4' + - 'PlayStation Portable' + - 'PlayStation Vita' + - 'Game Boy' + - 'Game Boy Color' + - 'Game Boy Advance' + - 'Nintendo DS' + - 'Nintendo DSi' + - 'Nintendo 3DS' + - 'Nintendo Entertainment System' + - 'Super Nintendo Entertainment System' + - 'Nintendo 64' + - 'GameCube' + - 'Wii' + - 'Wii U' + - 'Nintendo Switch' + - 'Windows' + - 'macOS' + - 'Linux' + - 'Sega Genesis' + - 'Sega Master System' + - 'Game Gear' + - 'Sega Saturn' + - 'Sega Dreamcast' + - 'Virtual Boy' diff --git a/test/faker/default/test_faker_internet.rb b/test/faker/default/test_faker_internet.rb index 06135cd92f..f35fe2ae51 100644 --- a/test/faker/default/test_faker_internet.rb +++ b/test/faker/default/test_faker_internet.rb @@ -280,4 +280,10 @@ def test_user_agent_with_invalid_argument assert @tester.user_agent(nil).match(/Mozilla|Opera/) assert @tester.user_agent(1).match(/Mozilla|Opera/) end + + def test_uuid + uuid = @tester.uuid + assert_equal(36, uuid.size) + assert_match(/\A\h{8}-\h{4}-4\h{3}-\h{4}-\h{12}\z/, uuid) + end end diff --git a/test/faker/games/test_game.rb b/test/faker/games/test_game.rb new file mode 100644 index 0000000000..7983837b7b --- /dev/null +++ b/test/faker/games/test_game.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative '../../test_helper' + +class TestFakerGame < Test::Unit::TestCase + def setup + @tester = Faker::Game + end + + def test_title + assert @tester.title.match(/\w+/) + end + + def test_genre + assert @tester.genre.match(/\w+/) + end + + def test_platform + assert @tester.platform.match(/\w+/) + end +end diff --git a/unreleased_README.md b/unreleased_README.md index cdfa656222..da318f3e34 100644 --- a/unreleased_README.md +++ b/unreleased_README.md @@ -231,6 +231,7 @@ gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master' - [Faker::Creature::Horse](doc/unreleased/creature/horse.md) ### Games + - [Faker::Game](doc/games/game.md) - [Faker::Games::Dota](doc/unreleased/games/dota.md) - [Faker::Games::ElderScrolls](doc/unreleased/games/elder_scrolls.md) - [Faker::Games::Fallout](doc/unreleased/games/fallout.md)