Class: CombineData
- Inherits:
-
Object
- Object
- CombineData
- Defined in:
- lib/clone_factory.rb
Instance Attribute Summary collapse
-
#boys ⇒ Object
Returns the value of attribute boys.
-
#data ⇒ Object
Returns the value of attribute data.
-
#girls ⇒ Object
Returns the value of attribute girls.
-
#last ⇒ Object
Returns the value of attribute last.
-
#num ⇒ Object
Returns the value of attribute num.
-
#street ⇒ Object
Returns the value of attribute street.
-
#zip_combos ⇒ Object
Returns the value of attribute zip_combos.
Instance Method Summary collapse
- #files ⇒ Object
- #generate ⇒ Object
- #get_data ⇒ Object
-
#initialize(num = 200) ⇒ CombineData
constructor
read files and out put several arrays and pull random values for each array.
- #return_random_boy ⇒ Object
- #return_random_girl ⇒ Object
-
#return_random_last_name_and_address ⇒ Object
zip,primary_city,state,area_codes.
Constructor Details
#initialize(num = 200) ⇒ CombineData
read files and out put several arrays and pull random values for each array
10 11 12 |
# File 'lib/clone_factory.rb', line 10 def initialize (num=200) @num = num end |
Instance Attribute Details
#boys ⇒ Object
Returns the value of attribute boys.
6 7 8 |
# File 'lib/clone_factory.rb', line 6 def boys @boys end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/clone_factory.rb', line 6 def data @data end |
#girls ⇒ Object
Returns the value of attribute girls.
6 7 8 |
# File 'lib/clone_factory.rb', line 6 def girls @girls end |
#last ⇒ Object
Returns the value of attribute last.
6 7 8 |
# File 'lib/clone_factory.rb', line 6 def last @last end |
#num ⇒ Object
Returns the value of attribute num.
6 7 8 |
# File 'lib/clone_factory.rb', line 6 def num @num end |
#street ⇒ Object
Returns the value of attribute street.
6 7 8 |
# File 'lib/clone_factory.rb', line 6 def street @street end |
#zip_combos ⇒ Object
Returns the value of attribute zip_combos.
6 7 8 |
# File 'lib/clone_factory.rb', line 6 def zip_combos @zip_combos end |
Instance Method Details
#files ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/clone_factory.rb', line 32 def files { boys: '../db/boys_names.csv', girls: '../db/girls_names.csv', last_names: '../db/last_names.csv', street_names: '../db/street_names.csv', zip_combinations: '../db/zip_combinations.csv', } end |
#generate ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/clone_factory.rb', line 14 def generate get_data number_of_boys = (@num / 2).to_i number_of_girls = (@num - number_of_boys).to_i return_val = [] number_of_boys.times { return_val << return_random_boy } number_of_girls.times { return_val << return_random_girl } return_val File.open("Cloned_Users.txt", "w+") do |f| return_val.each do |item| f.write("#{item}\n") end end end |
#get_data ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/clone_factory.rb', line 42 def get_data return_val = {} files.each do |k, v| d = ReadData.new(v).read_file return_val[k] = d end @data = return_val end |
#return_random_boy ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/clone_factory.rb', line 51 def return_random_boy return_val = return_random_last_name_and_address return_val[:first_name] = @data[:boys].sample(1)[0] return_val end |
#return_random_girl ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/clone_factory.rb', line 59 def return_random_girl return_val = return_random_last_name_and_address return_val[:first_name] = @data[:girls].sample(1)[0] return_val end |
#return_random_last_name_and_address ⇒ Object
zip,primary_city,state,area_codes
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/clone_factory.rb', line 68 def return_random_last_name_and_address ln = @data[:last_names].sample(1)[0] s = @data[:street_names].sample(1)[0] zc = @data[:zip_combinations].sample z = zc['zip'] c = zc['primary_city'] st = zc['state'] a = zc['area_code'] { last_name: ln, street: s, zip: z, city: c, state: st, area_code: a } end |