module DohData
Constants
- FIRST_OCTET
Public Instance Methods
random_alnum(count)
click to toggle source
# File lib/dohdata/basic.rb, line 23 def random_alnum(count) random_characters(count, 'abcdefghijklmnopqrstuvwxyz0123456789') end
random_amount(max, multiplier = 1)
click to toggle source
# File lib/dohdata/basic.rb, line 44 def random_amount(max, multiplier = 1) (random_int(max) + 1) * multiplier end
random_array_element(array)
click to toggle source
# File lib/dohdata/basic.rb, line 31 def random_array_element(array) array[random_int(array.size)] end
random_bank_account_number(max_size = 17)
click to toggle source
# File lib/dohdata/human.rb, line 116 def random_bank_account_number(max_size = 17) random_digits(random_range(5, max_size)) end
random_bank_routing_number()
click to toggle source
# File lib/dohdata/human.rb, line 112 def random_bank_routing_number random_element(@@bank_routing_numbers) end
random_birthday()
click to toggle source
# File lib/dohdata/human.rb, line 108 def random_birthday Date.new(1928 + random_int(56), random_int(12) + 1, random_int(27) + 1) end
random_bool()
click to toggle source
# File lib/dohdata/basic.rb, line 40 def random_bool random_element(true, false) end
random_characters(count, values_string)
click to toggle source
# File lib/dohdata/basic.rb, line 9 def random_characters(count, values_string) retval = '' count.times {retval += values_string.slice(random_int(values_string.size), 1)} retval end
random_city()
click to toggle source
# File lib/dohdata/human.rb, line 79 def random_city random_element(@@cities) end
random_country_code()
click to toggle source
# File lib/dohdata/human.rb, line 128 def random_country_code random_element(['USA', 'MEX', 'CAN']) end
random_date(min, max)
click to toggle source
# File lib/dohdata/basic.rb, line 52 def random_date(min, max) diff = (max + 1 - min) min + random_int(diff) end
random_digits(count)
click to toggle source
# File lib/dohdata/basic.rb, line 19 def random_digits(count) random_characters(count, '0123456789') end
random_element(*args)
click to toggle source
# File lib/dohdata/basic.rb, line 35 def random_element(*args) flat = args.flatten flat[random_int(flat.size)] end
random_email(first_name = nil, last_name = nil)
click to toggle source
# File lib/dohdata/human.rb, line 47 def random_email(first_name = nil, last_name = nil) domain = '@' + random_element(@@email_domains) + '.' + random_element(@@email_tlds) max_name_size = 50 - domain.size if first_name || last_name name = '' name += first_name.slice(0, random_range(1, first_name.size)) if first_name name += random_element('', '.', '_') if first_name && last_name name += last_name.slice(0, random_range(1, last_name.size)) if last_name name = name[0..(max_name_size-1)] max_num_size = max_name_size - name.size name += random_digits(random_range([7, max_num_size].min, [12, max_num_size].min)) else name_size = random_range([12, max_name_size].min, [16, max_name_size].min) name = random_letters(name_size) end name + domain end
random_employer_name()
click to toggle source
# File lib/dohdata/human.rb, line 120 def random_employer_name random_element(@@employers) end
random_first_name()
click to toggle source
# File lib/dohdata/human.rb, line 7 def random_first_name random_element(@@first_names) end
random_full_name()
click to toggle source
# File lib/dohdata/human.rb, line 43 def random_full_name random_first_name + ' ' + random_last_name end
random_generation()
click to toggle source
# File lib/dohdata/human.rb, line 15 def random_generation random_element(@@generation_options) end
random_int(max)
click to toggle source
implemented here so random behavior can be overridden by end user
# File lib/dohdata/basic.rb, line 5 def random_int(max) rand(max) end
random_ip_address()
click to toggle source
# File lib/dohdata/human.rb, line 133 def random_ip_address "#{random_element(FIRST_OCTET)}.#{random_int(256)}.#{random_int(256)}.#{random_int(256)}" end
random_last_name()
click to toggle source
# File lib/dohdata/human.rb, line 11 def random_last_name random_element(@@last_names) end
random_letters(count)
click to toggle source
# File lib/dohdata/basic.rb, line 15 def random_letters(count) random_characters(count, 'abcdefghijklmnopqrstuvwxyz') end
random_occupation()
click to toggle source
# File lib/dohdata/human.rb, line 27 def random_occupation random_element(@@occupations) end
random_percent(percent)
click to toggle source
# File lib/dohdata/basic.rb, line 48 def random_percent(percent) random_int(100) < percent end
random_range(min, max, multiplier = 1)
click to toggle source
# File lib/dohdata/basic.rb, line 27 def random_range(min, max, multiplier = 1) (random_int(max + 1 - min) + min) * multiplier end
random_relation()
click to toggle source
# File lib/dohdata/human.rb, line 124 def random_relation random_element(['cousin', 'mother', 'father', 'aunt', 'uncle', 'brother', 'sister', 'son', 'daughter']) end
random_ssn()
click to toggle source
# File lib/dohdata/human.rb, line 70 def random_ssn area = random_element(ssn_areas) highgroup = @@ssn_area_highgroups[area] highgroup_index = @@ssn_group_order.index(highgroup) possible_groups = @@ssn_group_order.slice(0..highgroup_index) group = random_element(possible_groups) area.to_s.rjust(3, '0') + group.to_s.rjust(2, '0') + random_range(1, 9999).to_s.rjust(4, '0') end
random_street()
click to toggle source
# File lib/dohdata/human.rb, line 104 def random_street random_street_number.to_s + ' ' + random_element('N','E','S','W') + ' ' + random_street_name + ' ' + random_street_type end
random_street_name()
click to toggle source
# File lib/dohdata/human.rb, line 83 def random_street_name random_element(@@street_names) end
random_street_number()
click to toggle source
# File lib/dohdata/human.rb, line 91 def random_street_number weight = random_int(10) if weight > 8 random_int(50000) elsif weight > 3 random_int(10000) elsif weight > 1 random_int(1000) else random_int(100) end end
random_street_type()
click to toggle source
# File lib/dohdata/human.rb, line 87 def random_street_type random_element(@@street_types) end
random_us_phone()
click to toggle source
# File lib/dohdata/human.rb, line 39 def random_us_phone random_range(200,999).to_s + '-' + random_digits(3) + '-' + random_digits(4) end
random_us_state()
click to toggle source
# File lib/dohdata/human.rb, line 31 def random_us_state (random_int(2) == 0) ? DohData::random_us_state_abbreviation : DohData::random_us_state_long_name end
random_us_state_abbreviation()
click to toggle source
# File lib/dohdata/human.rb, line 19 def random_us_state_abbreviation random_element(@@us_state_abbreviations) end
random_us_state_long_name()
click to toggle source
# File lib/dohdata/human.rb, line 23 def random_us_state_long_name random_element(@@us_state_long_names) end
random_us_zip()
click to toggle source
# File lib/dohdata/human.rb, line 35 def random_us_zip random_digits(5) + ((random_int(4) == 0) ? '-' + random_digits(4) : '') end
ssn_areas()
click to toggle source
# File lib/dohdata/human.rb, line 66 def ssn_areas @@ssn_areas ||= @@ssn_area_highgroups.keys end