Module: KittyNames

Defined in:
lib/kittynames.rb

Defined Under Namespace

Classes: Kitty

Class Method Summary collapse

Class Method Details

.domainObject



100
101
102
# File 'lib/kittynames.rb', line 100

def domain
  r domains
end

.domainsObject



104
105
106
# File 'lib/kittynames.rb', line 104

def domains
  @domains ||= ["d1g1t1ze.xyz", "bigBrwonBears.net", "philozophia.xyz", "whiskerrubies.net"]
end

.email(gender = nil) ⇒ Object



33
34
35
36
# File 'lib/kittynames.rb', line 33

def email(gender=nil)
  f, l = kittys_name(gender)
  email_for(f,l)
end

.email_for(f, l) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kittynames.rb', line 38

def email_for(f,l)
  if l
  r ["#{f.downcase}.#{l.downcase}@#{domain}",
    "#{f.split('').first.downcase}.#{l.downcase}@#{domain}"]
  else
    r ["#{f.downcase}.#{l.downcase}@#{domain}",
      "#{f.downcase}.#{l.downcase}@#{domain}",
      "#{f.split('').first.downcase}.#{l.downcase}@#{domain}",
      "#{f.split('').first.downcase}.#{l.downcase}@#{domain}",
      "#{f.split('').first.downcase}#{l.downcase}@#{domain}"]
  end
end

.female_nameObject



76
77
78
# File 'lib/kittynames.rb', line 76

def female_name
  r female_names
end

.female_namesObject



80
81
82
# File 'lib/kittynames.rb', line 80

def female_names
  @female_names ||= read_lines("female_names")
end

.first_name(gender = nil) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/kittynames.rb', line 60

def first_name(gender = nil)
  if gender
    (gender == :male ? male_names : female_names).shuffle.first
  else
    names.shuffle.first
  end
end

.kitty(gender = male_or_female?) ) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/kittynames.rb', line 24

def kitty(gender=male_or_female?)
  f = first_name(gender)
  l = last_name
  Kitty.new(:first_name => f,
              :last_name => l,
              :email => email_for(f,l),
              :gender => gender)
end

.kittys_name(gender = nil) ⇒ Object



51
52
53
54
# File 'lib/kittynames.rb', line 51

def kittys_name(gender=nil)
  gender ||= male_or_female?
  [first_name(gender), last_name]
end

.last_nameObject



92
93
94
# File 'lib/kittynames.rb', line 92

def last_name
  r last_names
end

.last_namesObject



96
97
98
# File 'lib/kittynames.rb', line 96

def last_names
  @last_names ||= read_lines("last_names")
end

.male_nameObject



84
85
86
# File 'lib/kittynames.rb', line 84

def male_name
  r male_names
end

.male_namesObject



88
89
90
# File 'lib/kittynames.rb', line 88

def male_names
  @male_names ||= read_lines("male_names")
end

.male_or_female?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/kittynames.rb', line 56

def male_or_female?
  rand > probability_of_male ? :female : :male
end

.nameObject



68
69
70
# File 'lib/kittynames.rb', line 68

def name
  r names
end

.namesObject



72
73
74
# File 'lib/kittynames.rb', line 72

def names
  @names ||= male_names + female_names
end

.probability_of_male(k = 0.41217441657656521951277712) ⇒ Object



4
5
6
# File 'lib/kittynames.rb', line 4

def probability_of_male(k=0.41217441657656521951277712)
  @probability_of_male ||= k
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/kittynames.rb', line 9

def seed(s=nil)
  if s.nil?
    if @seed.nil?
      @seed = (rand * 9999).to_i
      srand(@seed)
      @seed
    else
      @seed
    end
  else
    @seed = s
    srand(@seed)
  end
end