Class: Rubies::RandomHash
- Defined in:
- lib/rubies/random_hash.rb
Instance Method Summary collapse
- #children ⇒ Object
- #generate ⇒ Object
- #has_kids? ⇒ Boolean
- #hash_one ⇒ Object
- #hash_three ⇒ Object
- #hash_two ⇒ Object
-
#initialize ⇒ RandomHash
constructor
A new instance of RandomHash.
Methods inherited from MyHash
Constructor Details
#initialize ⇒ RandomHash
Returns a new instance of RandomHash.
16 17 18 |
# File 'lib/rubies/random_hash.rb', line 16 def initialize @ds = MyHash.new end |
Instance Method Details
#children ⇒ Object
20 21 22 23 24 25 26 |
# 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 ⇒ Object
70 71 72 |
# File 'lib/rubies/random_hash.rb', line 70 def generate @ds = [hash_one, hash_two, hash_three].sample end |
#has_kids? ⇒ Boolean
28 29 30 |
# File 'lib/rubies/random_hash.rb', line 28 def has_kids? rand(2) == 1 end |
#hash_one ⇒ Object
32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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 ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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 |