Class: CombineData

Inherits:
Object
  • Object
show all
Defined in:
lib/clone_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#boysObject

Returns the value of attribute boys.



6
7
8
# File 'lib/clone_factory.rb', line 6

def boys
  @boys
end

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/clone_factory.rb', line 6

def data
  @data
end

#girlsObject

Returns the value of attribute girls.



6
7
8
# File 'lib/clone_factory.rb', line 6

def girls
  @girls
end

#lastObject

Returns the value of attribute last.



6
7
8
# File 'lib/clone_factory.rb', line 6

def last
  @last
end

#numObject

Returns the value of attribute num.



6
7
8
# File 'lib/clone_factory.rb', line 6

def num
  @num
end

#streetObject

Returns the value of attribute street.



6
7
8
# File 'lib/clone_factory.rb', line 6

def street
  @street
end

#zip_combosObject

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

#filesObject



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

#generateObject



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_dataObject



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_boyObject



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_girlObject



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_addressObject

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