module RandomData::Names

Methods to create realistic-looking names

Public Instance Methods

company_name() click to toggle source
Alias for: companyname
companyname() click to toggle source

Returns a random company name

>> Random.company_name

“Harris & Thomas”

# File lib/random_data/names.rb, line 26
def companyname
  num = rand(5)
  if num == 0
    num = 1
  end
  final = num.times.collect { @@lastnames.rand.capitalize }

  if final.count == 1
    "#{final.first} #{@@company_types.rand}, #{@@incorporation_types.rand}"
  else
    incorporation_type = rand(17) % 2 == 0 ? @@incorporation_types.rand : nil
    company_type = rand(17) % 2 == 0 ? @@company_types.rand : nil
    trailer = company_type.nil? ? "" : " #{company_type}"
    trailer << ", #{incorporation_type}" unless incorporation_type.nil?
    "#{final[0..-1].join(', ')} & #{final.last}#{trailer}"
  end
end
Also aliased as: company_name
first_name() click to toggle source
Alias for: firstname
first_name_female() click to toggle source
Alias for: firstname_female
first_name_male() click to toggle source
Alias for: firstname_male
firstname() click to toggle source

Returns a random firstname

>> Random.firstname

“Sandra”

# File lib/random_data/names.rb, line 74
def firstname
  @@first_names.rand.capitalize
end
Also aliased as: first_name
firstname_female() click to toggle source

Returns a random female firstname

>> Random.firstname_female

“Mary”

# File lib/random_data/names.rb, line 98
def firstname_female
  @@female_first_names.rand.capitalize
end
Also aliased as: first_name_female
firstname_male() click to toggle source

Returns a random male firstname

>> Random.firstname_male

“James”

# File lib/random_data/names.rb, line 86
def firstname_male
  @@male_first_names.rand.capitalize
end
Also aliased as: first_name_male
full_name(options = { :initial => false, :gender => nil }) click to toggle source

Returns a random full name

# File lib/random_data/names.rb, line 104
def full_name(options = { :initial => false, :gender => nil })
  "#{first_name} #{last_name}"
end
initial() click to toggle source

Returns a random letter

# File lib/random_data/names.rb, line 8
def initial
  ('A'..'Z').to_a.rand
end
last_name() click to toggle source
Alias for: lastname
lastname() click to toggle source

Returns a random lastname

>> Random.lastname

“Harris”

# File lib/random_data/names.rb, line 51
def lastname
  @@lastnames.rand.capitalize
end
Also aliased as: last_name