Module: DataGenerationMachinery
- Defined in:
- lib/battleroom/helpers/data_generation_machinery.rb
Instance Method Summary collapse
- #gen_business ⇒ Object
- #gen_business_email_address(business_name) ⇒ Object
- #gen_business_name_under_16_characters ⇒ Object
- #gen_location ⇒ Object
- #gen_password ⇒ Object
- #gen_phone_number ⇒ Object
- #gen_random_names_array ⇒ Object
- #gen_user ⇒ Object
- #snake_case(string) ⇒ Object
Instance Method Details
#gen_business ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 79 def gen_business name_or_business_name = [:name, :business_name].sample email_key = [:email, :public_email, :info_email, :contact_email].sample web_key = [:url, :website, :homepage_url].sample address_key = [:street_address, :address].sample established_key = [:established].sample name = gen_business_name_under_16_characters email_address = gen_business_email_address(name) business = { name_or_business_name => name, email_key => email_address, web_key => Faker::Internet.url("#{name.parameterize}.com", ''), phone_num: gen_phone_number, address_key => Faker::Address.street_address, city: Faker::Address.city, state: Faker::Address.state_abbr, established_key => rand(1901..2014), } { data_structure: business, possible_variable_names: [ snake_case(name), snake_case(name), snake_case(name), 'client', ].shuffle } end |
#gen_business_email_address(business_name) ⇒ Object
65 66 67 68 69 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 65 def gen_business_email_address(business_name) possible_intro_words = ['info', 'hello', 'greetings', 'contact', 'team'] intro_word = possible_intro_words.sample "#{intro_word}@#{business_name.parameterize}.com" end |
#gen_business_name_under_16_characters ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 71 def gen_business_name_under_16_characters name = Faker::Company.name while name.length > 15 name = Faker::Company.name end name end |
#gen_location ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 108 def gen_location which_key_to_use = [:short, :long].sample latitude = { :short => :lat, :long => :latitude } longitude = { :short => :long, :long => :longitude } city = Faker::Address.city population = rand(130..270000) incorporated = population > 400 ? true : false location = { city: city, population: population, incorporated: incorporated, livestock: [true, false].sample, latitude[which_key_to_use] => Faker::Address.latitude.slice(0, rand(7..9)).to_f, longitude[which_key_to_use] => Faker::Address.longitude.slice(0, rand(7..9)).to_f } { data_structure: location, possible_variable_names: [ snake_case(city), 'home', 'target', 'destination', 'origin', 'locale', 'precinct', 'site', ].shuffle } end |
#gen_password ⇒ Object
26 27 28 29 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 26 def gen_password possible_chars = ('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a.map(&:to_s) possible_chars.shuffle[0, rand(6..8)].join end |
#gen_phone_number ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 13 def gen_phone_number "#{rand(1..9)} #{rand(0..9)} #{rand(0..9)}- #{rand(0..9)} #{rand(0..9)} #{rand(0..9)}- #{rand(0..9)} #{rand(0..9)} #{rand(0..9)} #{rand(0..9)}".gsub(" ", "").gsub("\n", "") end |
#gen_random_names_array ⇒ Object
7 8 9 10 11 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 7 def gen_random_names_array random_names_array = [] 200.times { random_names_array << Faker::Name.first_name } random_names_array.uniq end |
#gen_user ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 31 def gen_user password_or_pw = [:password, :pw].sample admin_or_is_admin = [:admin, :is_admin].sample phone_or_phone_num = [:phone, :phone_num, :phone_number].sample occupation_or_job_title = [:occupation, :job_title].sample zip_or_zip_code = [:zip, :zip_code].sample first_name = Faker::Name::first_name last_name = Faker::Name::last_name num_string = "#{[rand(0..9), rand(0..9), rand(0..9)][0, rand(1..4)].join}" user = { name: first_name + ' ' + last_name, username: Faker::Internet::user_name(first_name) + num_string, password_or_pw => gen_password, email: Faker::Internet.free_email(first_name), admin_or_is_admin => [true, false].sample, phone_or_phone_num => gen_phone_number, accepts_marketing: [true, false].sample, accepts_promotional_emails: [true, false].sample, occupation_or_job_title => Faker::Name.title, zip_or_zip_code => Faker::Address.zip } { data_structure: user, possible_variable_names: [ snake_case(first_name), snake_case(first_name), snake_case(first_name), snake_case(first_name), 'current_user' ].shuffle } end |
#snake_case(string) ⇒ Object
3 4 5 |
# File 'lib/battleroom/helpers/data_generation_machinery.rb', line 3 def snake_case(string) string.downcase.gsub(',', '').gsub(' ', '_').gsub('-', '_').gsub("'", '') end |