Class: RandomUser

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_hash(hash) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/random_user.rb', line 54

def self.create_from_hash(hash)
  user = RandomUser.new
  user.name =         hash['name']
  user.email =        hash['email']
  user.gender =       hash['gender']
  user.username =     hash['username']
  user.password =     hash['password']
  user.salt =         hash['salt']
  user.md5 =          hash['md5']
  user.sha1 =         hash['sha1']
  user.sha256 =       hash['sha256']
  user.dob =          Time.at(hash['dob'].to_i) if hash['dob']
  user.phone =        hash['phone']
  user.cell =         hash['cell']
  user.nationality =  hash['nationality']
  user.location =     hash['location']
  user.registered =   Time.at(hash['registered'].to_i) if hash['registered']
  user.picture =      hash['picture']
  return user if user.valid?
end

Instance Method Details

#first_nameObject



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

def first_name
  name["first"].capitalize if name["first"]
end

#formal_nameObject



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

def formal_name
  "#{name["title"]}. #{last_name}"
end

#full_formal_nameObject



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

def full_formal_name
  "#{name["title"]}. #{last_name}, #{first_name}"
end

#full_locationObject



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

def full_location
  "#{location["street"]}, #{location["city"]} #{location["postcode"]}, #{location["state"]}"
end

#full_nameObject



38
39
40
# File 'lib/random_user.rb', line 38

def full_name
  "#{first_name} #{last_name}"
end

#last_nameObject



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

def last_name
  name["last"].capitalize if name["last"]
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/random_user.rb', line 26

def valid?
  !email.nil? && !name.empty?
end