Module: BabyNames
- Defined in:
- lib/babynames.rb
Defined Under Namespace
Classes: Person
Class Method Summary collapse
- .domain ⇒ Object
- .domains ⇒ Object
- .email(gender = nil) ⇒ Object
- .email_for(f, l, m = nil) ⇒ Object
- .female_name ⇒ Object
- .female_names ⇒ Object
- .first_name(gender = nil) ⇒ Object
- .last_name ⇒ Object
- .last_names ⇒ Object
- .male_name ⇒ Object
- .male_names ⇒ Object
- .male_or_female? ⇒ Boolean
- .middle_name(gender = nil) ⇒ Object
- .name ⇒ Object
- .names ⇒ Object
- .person(gender = male_or_female?) ) ⇒ Object
- .persons_name(gender = nil) ⇒ Object
- .probability_of_male(z = 0.51219512195122) ⇒ Object
-
.seed(s = nil) ⇒ Object
Set the seed or use randomly.
Class Method Details
.domain ⇒ Object
106 107 108 |
# File 'lib/babynames.rb', line 106 def domain r domains end |
.domains ⇒ Object
110 111 112 |
# File 'lib/babynames.rb', line 110 def domains @domains ||= ["gma1l.com", "yah0o.com", "m5n.com", "h0tmail.com"] end |
.email(gender = nil) ⇒ Object
35 36 37 38 |
# File 'lib/babynames.rb', line 35 def email(gender=nil) f, l = persons_name(gender) email_for(f,l) end |
.email_for(f, l, m = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/babynames.rb', line 40 def email_for(f,l,m=nil) if m.nil? r ["#{f.downcase}.#{l.downcase}@#{domain}", "#{f.split('').first.downcase}.#{l.downcase}@#{domain}"] else r ["#{f.downcase}.#{l.downcase}@#{domain}", "#{f.downcase}.#{m.split('').first.downcase}.#{l.downcase}@#{domain}", "#{f.split('').first.downcase}.#{l.downcase}@#{domain}", "#{f.split('').first.downcase}.#{m.split('').first.downcase}.#{l.downcase}@#{domain}", "#{f.split('').first.downcase}#{m.split('').first.downcase}#{l.downcase}@#{domain}"] end end |
.female_name ⇒ Object
82 83 84 |
# File 'lib/babynames.rb', line 82 def female_name r female_names end |
.female_names ⇒ Object
86 87 88 |
# File 'lib/babynames.rb', line 86 def female_names @female_names ||= read_lines("female_names") end |
.first_name(gender = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/babynames.rb', line 66 def first_name(gender = nil) if gender (gender == :male ? male_names : female_names).shuffle.first else names.shuffle.first end end |
.last_name ⇒ Object
98 99 100 |
# File 'lib/babynames.rb', line 98 def last_name r last_names end |
.last_names ⇒ Object
102 103 104 |
# File 'lib/babynames.rb', line 102 def last_names @last_names ||= read_lines("last_names") end |
.male_name ⇒ Object
90 91 92 |
# File 'lib/babynames.rb', line 90 def male_name r male_names end |
.male_names ⇒ Object
94 95 96 |
# File 'lib/babynames.rb', line 94 def male_names @male_names ||= read_lines("male_names") end |
.male_or_female? ⇒ Boolean
58 59 60 |
# File 'lib/babynames.rb', line 58 def male_or_female? rand > probability_of_male ? :female : :male end |
.middle_name(gender = nil) ⇒ Object
62 63 64 |
# File 'lib/babynames.rb', line 62 def middle_name(gender=nil) first_name(gender) end |
.name ⇒ Object
74 75 76 |
# File 'lib/babynames.rb', line 74 def name r names end |
.names ⇒ Object
78 79 80 |
# File 'lib/babynames.rb', line 78 def names @names ||= male_names + female_names end |
.person(gender = male_or_female?) ) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/babynames.rb', line 24 def person(gender=male_or_female?) f = first_name(gender) m = middle_name(gender) l = last_name Person.new(:first_name => f, :middle_name => m, :last_name => l, :email => email_for(f,l,m), :gender => gender) end |
.persons_name(gender = nil) ⇒ Object
53 54 55 56 |
# File 'lib/babynames.rb', line 53 def persons_name(gender=nil) gender ||= male_or_female? [first_name(gender), last_name] end |
.probability_of_male(z = 0.51219512195122) ⇒ Object
4 5 6 |
# File 'lib/babynames.rb', line 4 def probability_of_male(z=0.51219512195122) @probability_of_male ||= z end |
.seed(s = nil) ⇒ Object
Set the seed or use randomly
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/babynames.rb', line 9 def seed(s=nil) if s.nil? if @seed.nil? @seed = (rand * 10000).to_i srand(@seed) @seed else @seed end else @seed = s srand(@seed) end end |