├── .gitignore ├── db ├── colors.txt ├── activities.txt ├── foods.txt ├── given_names.male.txt ├── given_names.female.txt └── surnames.txt ├── lib ├── fake_person │ ├── gender.rb │ ├── color.rb │ ├── foods.rb │ ├── activities.rb │ ├── avatar.rb │ ├── date_of_birth.rb │ ├── email.rb │ ├── username.rb │ ├── titles.rb │ ├── likes.rb │ └── names.rb └── fake_person.rb ├── fake_person.gemspec └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | 3 | -------------------------------------------------------------------------------- /db/colors.txt: -------------------------------------------------------------------------------- 1 | red 2 | blue 3 | pink 4 | purple 5 | mauve 6 | yellow 7 | orange 8 | red 9 | turquoise 10 | beige -------------------------------------------------------------------------------- /lib/fake_person/gender.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | # 4 | # Return the gender for this person 5 | # 6 | def gender 7 | @gender ||= rand(2) == 0 ? :male : :female 8 | end 9 | 10 | end -------------------------------------------------------------------------------- /lib/fake_person/color.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | def favorite_color 4 | self.class.colors.sample 5 | end 6 | 7 | def self.colors 8 | @colors ||= begin 9 | path = File.expand_path(File.join('..', '..', '..', 'db', "colors.txt"), __FILE__) 10 | File.read(path).split("\n").compact.map(&:capitalize) 11 | end 12 | end 13 | 14 | 15 | end -------------------------------------------------------------------------------- /lib/fake_person/foods.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | def favorite_food 4 | @favorite_food ||= self.class.foods.sample 5 | end 6 | 7 | def self.foods 8 | @foods ||= begin 9 | path = File.expand_path(File.join('..', '..', '..', 'db', "foods.txt"), __FILE__) 10 | File.read(path).split("\n").compact.map(&:capitalize) 11 | end 12 | end 13 | 14 | end -------------------------------------------------------------------------------- /lib/fake_person.rb: -------------------------------------------------------------------------------- 1 | require 'fake_person/names' 2 | require 'fake_person/gender' 3 | require 'fake_person/titles' 4 | require 'fake_person/username' 5 | require 'fake_person/date_of_birth' 6 | require 'fake_person/email' 7 | require 'fake_person/activities' 8 | require 'fake_person/foods' 9 | require 'fake_person/likes' 10 | require 'fake_person/color' 11 | require 'fake_person/avatar' -------------------------------------------------------------------------------- /lib/fake_person/activities.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | def favorite_activity 4 | @favorite_activity ||= self.class.activities.sample 5 | end 6 | 7 | def self.activities 8 | @activities ||= begin 9 | path = File.expand_path(File.join('..', '..', '..', 'db', "activities.txt"), __FILE__) 10 | File.read(path).split("\n").compact.map(&:capitalize) 11 | end 12 | end 13 | 14 | end -------------------------------------------------------------------------------- /fake_person.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = "fake_person" 3 | s.description = %q{A Ruby library for creating fake personalities} 4 | s.summary = s.description 5 | s.homepage = "https://github.com/adamcooke/fake-person" 6 | s.licenses = ['MIT'] 7 | s.version = "1.0.2" 8 | s.files = Dir.glob("{lib,db}/**/*") 9 | s.require_paths = ["lib"] 10 | s.authors = ["Adam Cooke"] 11 | s.email = ["me@adamcooke.io"] 12 | end 13 | -------------------------------------------------------------------------------- /lib/fake_person/avatar.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | AVATAR_QUANTITIES = {:male => 76, :female => 65} 4 | AVATAR_SIZE_GROUPS = [128, 256, 512] 5 | 6 | def avatar_identifier 7 | @avatar_identifier ||= rand(AVATAR_QUANTITIES[self.gender]) 8 | end 9 | 10 | def avatar_url(options = {}) 11 | options[:size] ||= 128 12 | closest_size = AVATAR_SIZE_GROUPS.select {|s| s >= options[:size]}.first 13 | "#{options[:secure] == false ? 'http' : 'https'}://s3-eu-west-1.amazonaws.com/fakepeople/#{gender}/#{closest_size}/#{avatar_identifier}.png" 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/fake_person/date_of_birth.rb: -------------------------------------------------------------------------------- 1 | require 'date' 2 | 3 | class FakePerson 4 | 5 | # 6 | # Return the person's date of birth 7 | # 8 | def date_of_birth(min_age = 18, max_age = 80) 9 | @date_of_birth ||= Date.new(Date.today.year - max_age + rand(max_age - min_age), rand(12) + 1, rand(28) + 1) 10 | end 11 | 12 | # 13 | # Return this person's age 14 | # 15 | def age 16 | @age ||= begin 17 | years = Date.today.year - self.date_of_birth.year 18 | years -= 1 if Date.today.yday < self.date_of_birth.yday 19 | years 20 | end 21 | end 22 | 23 | end -------------------------------------------------------------------------------- /db/activities.txt: -------------------------------------------------------------------------------- 1 | astronomy 2 | bathing 3 | camping 4 | climbing 5 | coding 6 | debugging 7 | dog racing 8 | drinking 9 | driving 10 | figure skating 11 | gaming 12 | geocaching 13 | gongoozing 14 | hiking 15 | homebrewing 16 | jogging 17 | juggling 18 | kitesurfing 19 | knitting 20 | nordic skating 21 | paintballing 22 | painting 23 | photography 24 | playing chess 25 | playing darts 26 | puzzles 27 | rambling 28 | reading 29 | roller skating 30 | sailing 31 | sewing 32 | shooting 33 | shopping 34 | singing 35 | slot-car racing 36 | stamp collecting 37 | taxidermy 38 | training mice 39 | trainspotting 40 | visiting museums 41 | watching television 42 | writing 43 | yo-yoing -------------------------------------------------------------------------------- /db/foods.txt: -------------------------------------------------------------------------------- 1 | apples 2 | bacon 3 | baked beans 4 | basil 5 | beer 6 | biscuits 7 | bloody mary 8 | burritos 9 | cake 10 | calzone 11 | cheese 12 | chicken 13 | chinese food 14 | chips 15 | chocolate 16 | cider 17 | coffee 18 | cola 19 | cornettos 20 | cottage pie 21 | courgettes 22 | couscous 23 | cream 24 | crisps 25 | crumbs off of the floor 26 | curry 27 | custard 28 | dried fruit 29 | fish fingers 30 | ginger 31 | ham 32 | jam 33 | lamb 34 | lasagna 35 | leeks 36 | lemondade 37 | lobster thermadore 38 | marshmallows 39 | mushrooms 40 | mussels 41 | oysters 42 | pasta 43 | peanuts 44 | pears 45 | pizza 46 | popcorn 47 | pork 48 | potatoes 49 | puff pastry 50 | risotto 51 | rum 52 | salami 53 | salmon 54 | spaghetti 55 | steak 56 | stew 57 | tea 58 | tomatoes 59 | veal 60 | vodka -------------------------------------------------------------------------------- /lib/fake_person/email.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | # 4 | # Return an email address for this person. All messages sent to example.com 5 | # will bounce. 6 | # 7 | def email_address(domain = 'example.com') 8 | @email_address ||= "#{username}@#{domain}" 9 | end 10 | 11 | # 12 | # Return a free email address. This might be a real person! 13 | # 14 | def free_email_address 15 | @free_email_address ||= "#{username}@#{self.class.free_email_domains.shuffle.first}" 16 | end 17 | 18 | class << self 19 | 20 | # 21 | # Return an array of free email hosting domains 22 | # 23 | def free_email_domains 24 | @free_email_domains ||= ["hotmail.com", "gmail.com", "yahoo.com", "gmx.com"] 25 | end 26 | 27 | end 28 | 29 | end -------------------------------------------------------------------------------- /lib/fake_person/username.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | # 4 | # Return a username which this user can be assigned. 5 | # 6 | def username 7 | @username ||= begin 8 | case rand(7) 9 | when 0 then "#{first_name.downcase}.#{last_name.downcase}" 10 | when 1 then "#{first_name.downcase[0,1]}#{last_name.downcase}" 11 | when 2 then "#{last_name.downcase}-#{first_name.downcase}" 12 | when 3 then "#{first_name.downcase}#{last_name.downcase}" 13 | when 4 then "#{first_name.downcase[0,1]}.#{middle_name.downcase[0,1]}.#{last_name.downcase}" 14 | when 5 then "#{first_name.downcase}#{date_of_birth.year.to_s[2,2]}" 15 | when 6 then "#{first_name.downcase}#{last_name.downcase}#{date_of_birth.year}" 16 | end 17 | end 18 | end 19 | 20 | end -------------------------------------------------------------------------------- /db/given_names.male.txt: -------------------------------------------------------------------------------- 1 | aaron 2 | adam 3 | adrian 4 | aidan 5 | aiden 6 | alex 7 | alexander 8 | alfie 9 | alfred 10 | archibald 11 | ben 12 | benjamin 13 | brandon 14 | brian 15 | charles 16 | charlie 17 | chris 18 | christian 19 | christopher 20 | dan 21 | daniel 22 | dave 23 | david 24 | dom 25 | dominic 26 | ed 27 | edward 28 | ethan 29 | gavin 30 | harry 31 | jack 32 | jacob 33 | jake 34 | james 35 | joe 36 | john 37 | jon 38 | jonathan 39 | joseph 40 | josh 41 | joshua 42 | julian 43 | justin 44 | kev 45 | kevin 46 | liam 47 | luke 48 | martin 49 | matthew 50 | michael 51 | mike 52 | nathan 53 | nicholas 54 | nick 55 | noah 56 | oliver 57 | olly 58 | owen 59 | preston 60 | richard 61 | ryan 62 | sam 63 | samuel 64 | stephen 65 | steve 66 | steven 67 | thomas 68 | tom 69 | william 70 | zach 71 | zachary -------------------------------------------------------------------------------- /lib/fake_person/titles.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | # 4 | # Return a title 5 | # 6 | def title 7 | @title ||= begin 8 | base = (gender == :male ? self.class.male_titles : self.class.female_titles) 9 | base = base | self.class.unisex_titles if rand(5) == 0 10 | base.shuffle.first 11 | end 12 | end 13 | 14 | class << self 15 | 16 | # 17 | # Return all unisex titles 18 | # 19 | def unisex_titles 20 | @unisex_titles ||= ['Dr', 'Prof', 'Rev'] 21 | end 22 | 23 | # 24 | # Return all male titles 25 | # 26 | def male_titles 27 | @male_titles ||= ['Mr'] 28 | end 29 | 30 | # 31 | # Return all female titles 32 | # 33 | def female_titles 34 | @female_titles ||= ['Mrs', 'Miss', 'Ms'] 35 | end 36 | 37 | end 38 | 39 | end -------------------------------------------------------------------------------- /lib/fake_person/likes.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | def likes(count=3) 4 | @likes ||= begin 5 | if count == 1 6 | [favorite_activity] 7 | elsif count == 2 8 | [favorite_activity, favorite_food] 9 | else 10 | [favorite_activity, favorite_food] + activities_and_foods(count - 2, @dislikes) 11 | end 12 | end 13 | end 14 | 15 | def dislikes(count=3) 16 | @dislikes ||= activities_and_foods(count, @likes) 17 | end 18 | 19 | private 20 | 21 | def activities_and_foods(count, exclusion_list=nil) 22 | exclusion_list ||= [] 23 | 24 | num_activities_to_get = (1..count).to_a.sample 25 | num_foods_to_get = (count - num_activities_to_get) 26 | 27 | (self.class.activities - exclusion_list).sample(num_activities_to_get) + (self.class.foods - exclusion_list).sample(num_foods_to_get) 28 | end 29 | 30 | end -------------------------------------------------------------------------------- /db/given_names.female.txt: -------------------------------------------------------------------------------- 1 | abby 2 | abi 3 | abigail 4 | alex 5 | alexandra 6 | alexis 7 | alice 8 | alison 9 | amy 10 | andrea 11 | anna 12 | annabelle 13 | anne 14 | arabella 15 | ariana 16 | ava 17 | bella 18 | brooke 19 | claire 20 | caroline 21 | catherine 22 | charlotte 23 | chloe 24 | clara 25 | edith 26 | eleanor 27 | elise 28 | elizabeth 29 | elizabeth 30 | ella 31 | emily 32 | emma 33 | felicity 34 | florence 35 | grace 36 | hailey 37 | hallie 38 | harriet 39 | heidi 40 | holly 41 | imogen 42 | isabella 43 | josie 44 | julia 45 | kaylee 46 | lara 47 | leah 48 | lily 49 | lottie 50 | lou 51 | louisa 52 | louise 53 | lucy 54 | mel 55 | melanie 56 | melissa 57 | mia 58 | millie 59 | molly 60 | mya 61 | natalie 62 | nicole 63 | nina 64 | olivia 65 | paige 66 | phoebe 67 | pixie 68 | rachel 69 | rose 70 | sara 71 | sarah 72 | sophia 73 | stefanie 74 | steph 75 | stephanie 76 | vanessa 77 | vicky 78 | victoria 79 | violet 80 | zoe 81 | zoey -------------------------------------------------------------------------------- /db/surnames.txt: -------------------------------------------------------------------------------- 1 | adams 2 | allen 3 | anderson 4 | andrews 5 | bailey 6 | baker 7 | bell 8 | bennett 9 | brown 10 | butler 11 | campbell 12 | carter 13 | chapman 14 | clark 15 | clarke 16 | cole 17 | collins 18 | cooke 19 | cooper 20 | cox 21 | davies 22 | davis 23 | dean 24 | edwards 25 | ellis 26 | evans 27 | foster 28 | fox 29 | graphan 30 | gray 31 | green 32 | griffiths 33 | hall 34 | harris 35 | harrison 36 | harvey 37 | hill 38 | holmes 39 | hudon 40 | hughes 41 | hunt 42 | hunter 43 | jackson 44 | james 45 | johnson 46 | jones 47 | kelly 48 | kennedy 49 | king 50 | knight 51 | lee 52 | lewis 53 | lloyd 54 | marshall 55 | martin 56 | mason 57 | matthews 58 | miller 59 | mitchell 60 | moore 61 | morgan 62 | morris 63 | murphy 64 | murray 65 | owen 66 | palmer 67 | parker 68 | pearce 69 | phillips 70 | poole 71 | powell 72 | price 73 | reid 74 | reynolds 75 | richards 76 | richardson 77 | roberts 78 | robertson 79 | robinson 80 | rogers 81 | rose 82 | ross 83 | russel 84 | saunders 85 | scott 86 | shaw 87 | simpson 88 | smith 89 | stevens 90 | stewart 91 | talyor 92 | thomas 93 | thompson 94 | thomson 95 | turner 96 | walker 97 | walsh 98 | ward 99 | watson 100 | white 101 | wilkinson 102 | williams 103 | wilson 104 | wood 105 | wright 106 | young -------------------------------------------------------------------------------- /lib/fake_person/names.rb: -------------------------------------------------------------------------------- 1 | class FakePerson 2 | 3 | # 4 | # Return a full name 5 | # 6 | def name(format = :standard) 7 | case format 8 | when :standard then "#{first_name} #{last_name}" 9 | when :full then "#{first_name} #{middle_name} #{last_name}" 10 | when :formal then "#{title}. #{last_name}" 11 | when :formal_with_first then "#{title}. #{first_name} #{last_name}" 12 | end 13 | end 14 | 15 | # 16 | # Return the initials 17 | # 18 | def initials 19 | "#{first_name[0,1]}#{middle_name[0,1]}#{last_name[0,1]}" 20 | end 21 | 22 | # 23 | # Return the first name 24 | # 25 | def first_name 26 | @first_name ||= self.class.given_names(self.gender).shuffle.first 27 | end 28 | 29 | # 30 | # Return the middle name 31 | # 32 | def middle_name 33 | @middle_name ||= begin 34 | while @middle_name.nil? || @middle_name == self.first_name 35 | @middle_name = self.class.given_names(self.gender).shuffle.first 36 | end 37 | @middle_name 38 | end 39 | end 40 | 41 | # 42 | # Return the last name 43 | # 44 | def last_name 45 | @last_name ||= begin 46 | while @last_name.nil? || @last_name == self.first_name || @last_name == self.middle_name 47 | @last_name = self.class.surnames.shuffle.first 48 | end 49 | @last_name 50 | end 51 | end 52 | 53 | class << self 54 | 55 | # 56 | # Return an array of all possible first names 57 | # 58 | def given_names(gender) 59 | @given_names ||= {} 60 | @given_names[gender.to_sym] ||= begin 61 | path = File.expand_path(File.join('..', '..', '..', 'db', "given_names.#{gender}.txt"), __FILE__) 62 | File.read(path).split("\n").compact.map(&:capitalize) 63 | end 64 | end 65 | 66 | # 67 | # Return an array of all possible last names 68 | # 69 | def surnames 70 | @surnames ||= begin 71 | path = File.expand_path(File.join('..', '..', '..', 'db', "surnames.txt"), __FILE__) 72 | File.read(path).split("\n").compact.map(&:capitalize) 73 | end 74 | end 75 | 76 | end 77 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fake Person 2 | 3 | This is a gem which will generate a "person" object for a completely make up human being. The primary reason for creating this is gem is for the Rails Rumble competition where we need to be able to generate fake personalities to allow judges to use our application. 4 | 5 | ## Installation 6 | 7 | Just put the following in your Gemfile and run `bundle`. 8 | 9 | ```ruby 10 | gem "fake_person", "~> 1.0" 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```ruby 16 | person = FakePerson.new 17 | 18 | # Names 19 | person.first_name #=> "Alexander" 20 | person.middle_name #=> "James" 21 | person.last_name #=> "Smith" 22 | person.name #=> "Alexander Smith" 23 | person.name(:full) #=> "Alexander James Smith" 24 | person.initials #=> "AJS" 25 | 26 | # Titles 27 | person.title #=> "Mr" 28 | person.name(:formal) #=> "Mr Smith" 29 | person.name(:formal_with_first) #=> "Mr Alexander Smith" 30 | 31 | # Gender 32 | person.gender #=> :male (or :female) 33 | 34 | # Date of birth 35 | person.date_of_birth #=> # 36 | person.age #=> 37 37 | 38 | # Usernames 39 | person.username #=> "alexsmith" (various styles exist) 40 | 41 | # E-Mail Addresses 42 | person.email_address #=> "alexsmith@example.com" 43 | person.free_email_address #=> "alexsmith@gmail.com" (or various other free providers) 44 | 45 | # Activities 46 | person.favorite_activity #=> "Figure skating" 47 | 48 | # Foods 49 | person.favorite_food #=> "Pizza" 50 | 51 | # Likes/Dislikes 52 | person.likes(3) #=> ['Driving', 'Fish fingers', 'Jogging'] 53 | person.dislikes(2) #=> ['Kitesurfing', 'Coffee'] 54 | 55 | # Colour 56 | person.favorite_color #=> "Purple" 57 | 58 | # Avatars 59 | person.avatar_url #=> "https://s3-eu-west-1.amazonaws.com/fakepeople/male/256/57.png" 60 | ``` 61 | 62 | ## Why not Faker? 63 | 64 | Faker is great and everything but the data it generates can be a little strange. This library uses some of the most popular given & surnames in the US & UK. 65 | --------------------------------------------------------------------------------