Module: DataGenerationMachinery
- Defined in:
- lib/battleroom/data_generation_machinery.rb
Instance Method Summary collapse
- #gen_app ⇒ Object
- #gen_business ⇒ Object
- #gen_business_email_address(business_name) ⇒ 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_app ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/battleroom/data_generation_machinery.rb', line 31 def gen_app = [:author, :creator].sample release_or_stable_release = [:release, :stable_release].sample name_or_title = [:name, :title, :app_name].sample name = Faker::App.name app = { version: Faker::App.version, => Faker::App., name_or_title => name, release_or_stable_release => rand(2004..2014), open_source: [true, false].sample } data = { data_structure: app, possible_variable_names: [ snake_case(name), 'app', 'application' ].shuffle } end |
#gen_business ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/battleroom/data_generation_machinery.rb', line 94 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, :inception_year].sample name = Faker::Company.name email_address = gen_business_email_address(name) business = { name_or_business_name => name, public_email: 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 = { 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
88 89 90 91 92 |
# File 'lib/battleroom/data_generation_machinery.rb', line 88 def gen_business_email_address(business_name) possible_intro_words = ['info', 'hello', 'greetings', 'contact', 'team'] intro_word = possible_intro_words.sample biz_email_address = "#{intro_word}@#{business_name.parameterize}.com" end |
#gen_location ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/battleroom/data_generation_machinery.rb', line 123 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 = { 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/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/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/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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/battleroom/data_generation_machinery.rb', line 54 def gen_user password_or_pw = [:password, :pw].sample admin_or_is_admin = [:admin, :is_admin].sample phone_of_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_of_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 = { 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/data_generation_machinery.rb', line 3 def snake_case(string) string.downcase.gsub(',', '').gsub(' ', '_').gsub('-', '_').gsub("'", '') end |