class Rubies::RandomHash

Public Class Methods

new() click to toggle source
# File lib/rubies/random_hash.rb, line 16
def initialize
  @ds = MyHash.new
end

Public Instance Methods

children() click to toggle source
# File lib/rubies/random_hash.rb, line 20
def children
  array = Array.new
  rand(1..3).times do
    array << Faker::Name.first_name
  end
  array
end
generate() click to toggle source
# File lib/rubies/random_hash.rb, line 70
def generate
  @ds = [hash_one, hash_two, hash_three].sample
end
has_kids?() click to toggle source
# File lib/rubies/random_hash.rb, line 28
def has_kids?
  rand(2) == 1
end
hash_one() click to toggle source
# File lib/rubies/random_hash.rb, line 32
def hash_one
  hash = Hash.new
  10.times do
    name = Faker::Company.name
    bs = Faker::Company.bs
    hash[name] = bs
  end
  hash
end
hash_three() click to toggle source
# File lib/rubies/random_hash.rb, line 52
def hash_three
  hash = MyHash.new
  length = rand(1..5)
  count = 1
  while count <= length
    details = Hash.new
    name = Faker::Name.name
    phone = Faker::PhoneNumber.cell_phone
    company = Faker::Company.name
    details["phone"] = phone
    details["company"] = company
    details["children"] = children if has_kids?
    hash[name] = details
    count += 1
  end
  hash
end
hash_two() click to toggle source
# File lib/rubies/random_hash.rb, line 42
def hash_two
  hash = MyHash.new
  10.times do
    email = Faker::Internet.email
    num = rand(1..1000)
    hash[email] = num
  end
  hash
end