Class: RandomUser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRandomUser

Returns a new instance of RandomUser.



7
8
9
10
11
# File 'lib/randomizer/random_user.rb', line 7

def initialize
  names = NameGenerator.instance.random
  @first_name = names.first
  @last_name = names.last
end

Instance Attribute Details

#first_nameObject (readonly)

Returns the value of attribute first_name.



5
6
7
# File 'lib/randomizer/random_user.rb', line 5

def first_name
  @first_name
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



5
6
7
# File 'lib/randomizer/random_user.rb', line 5

def last_name
  @last_name
end

Class Method Details

.nicknames(first, last) ⇒ Object



53
54
55
56
# File 'lib/randomizer/random_user.rb', line 53

def self.nicknames(first, last)
  first, last = first.downcase, last.downcase
  [first, last, first[0..0] + last, first + last[0..0], first + last, first + '2', first + '3']
end

Instance Method Details

#avatar_urlObject

AVATAR



21
22
23
# File 'lib/randomizer/random_user.rb', line 21

def avatar_url
  @avatar_url ||= AllAvatarsSite.instance.random_url
end

#emailObject

EMAIL ADDRESS



62
63
64
# File 'lib/randomizer/random_user.rb', line 62

def email
  @email || regenerate_email
end

#full_nameObject



13
14
15
# File 'lib/randomizer/random_user.rb', line 13

def full_name
  @full_name ||= [@first_name, @last_name].join(' ')
end

#nicknameObject

NICKNAME



41
42
43
# File 'lib/randomizer/random_user.rb', line 41

def nickname
  @nickname || regenerate_nickname
end

#passwordObject

PASSWORD



29
30
31
# File 'lib/randomizer/random_user.rb', line 29

def password
  @password ||= random_password
end

#random_email_domainObject



70
71
72
# File 'lib/randomizer/random_user.rb', line 70

def random_email_domain
  EMAIL_DOMAINS.random
end

#random_nicknameObject



49
50
51
# File 'lib/randomizer/random_user.rb', line 49

def random_nickname
  RandomUser.nicknames(@first_name, @last_name).random
end

#random_passwordObject



33
34
35
# File 'lib/randomizer/random_user.rb', line 33

def random_password
  Array.new(8, '').collect{PASSWORD_CHARACTERS.random}.join
end

#regenerate_emailObject



66
67
68
# File 'lib/randomizer/random_user.rb', line 66

def regenerate_email
  @email = random_nickname + '@' + random_email_domain
end

#regenerate_nicknameObject



45
46
47
# File 'lib/randomizer/random_user.rb', line 45

def regenerate_nickname
  @nickname = random_nickname
end