Module: RandomData::Names

Included in:
Random
Defined in:
lib/random_data/names.rb

Overview

Methods to create realistic-looking names

Constant Summary collapse

@@lastnames =
%w(ABEL ANDERSON ANDREWS ANTHONY BAKER BROWN BURROWS CLARK CLARKE CLARKSON DAVIDSON DAVIES DAVIS 
DENT EDWARDS GARCIA GRANT HALL HARRIS HARRISON JACKSON JEFFRIES JEFFERSON JOHNSON JONES 
KIRBY KIRK LAKE LEE LEWIS MARTIN MARTINEZ MAJOR MILLER MOORE OATES PETERS PETERSON ROBERTSON 
ROBINSON RODRIGUEZ SMITH SMYTHE STEVENS TAYLOR THATCHER THOMAS THOMPSON WALKER WASHINGTON WHITE 
WILLIAMS WILSON YORKE)
@@incorporation_types =
%w{LLC Inc Inc. Ltd. LP LLP Corp. PLLC}
@@company_types =
%w{Clothier Publishing Computing Consulting Engineering Industries Marketing Manufacturing}
@@male_first_names =
%w(ADAM ANTHONY ARTHUR BRIAN CHARLES CHRISTOPHER DANIEL DAVID DONALD EDGAR EDWARD EDWIN 
GEORGE HAROLD HERBERT HUGH JAMES JASON JOHN JOSEPH KENNETH KEVIN MARCUS MARK MATTHEW 
MICHAEL PAUL PHILIP RICHARD ROBERT ROGER RONALD SIMON STEVEN TERRY THOMAS WILLIAM)
@@female_first_names =
%w(ALISON ANN ANNA ANNE BARBARA BETTY BERYL CAROL CHARLOTTE CHERYL DEBORAH DIANA DONNA 
DOROTHY ELIZABETH EVE FELICITY FIONA HELEN HELENA JENNIFER JESSICA JUDITH KAREN KIMBERLY 
LAURA LINDA LISA LUCY MARGARET MARIA MARY MICHELLE NANCY PATRICIA POLLY ROBYN RUTH SANDRA 
SARAH SHARON SUSAN TABITHA URSULA VICTORIA WENDY)
@@first_names =
@@male_first_names + @@female_first_names

Instance Method Summary collapse

Instance Method Details

#companynameObject Also known as: company_name

Returns a random company name

>> Random.company_name

“Harris & Thomas”



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

#firstnameObject Also known as: first_name

Returns a random firstname

>> Random.firstname

“Sandra”



74
75
76
# File 'lib/random_data/names.rb', line 74

def firstname
  @@first_names.rand.capitalize
end

#firstname_femaleObject Also known as: first_name_female

Returns a random female firstname

>> Random.firstname_female

“Mary”



98
99
100
# File 'lib/random_data/names.rb', line 98

def firstname_female
  @@female_first_names.rand.capitalize
end

#firstname_maleObject Also known as: first_name_male

Returns a random male firstname

>> Random.firstname_male

“James”



86
87
88
# File 'lib/random_data/names.rb', line 86

def firstname_male
  @@male_first_names.rand.capitalize
end

#full_name(options = { :initial => false, :gender => nil }) ⇒ Object

Returns a random full name



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

def full_name(options = { :initial => false, :gender => nil })
  "#{first_name} #{last_name}"
end

#initialObject

Returns a random letter



8
9
10
# File 'lib/random_data/names.rb', line 8

def initial
  ('A'..'Z').to_a.rand
end

#lastnameObject Also known as: last_name

Returns a random lastname

>> Random.lastname

“Harris”



51
52
53
# File 'lib/random_data/names.rb', line 51

def lastname
  @@lastnames.rand.capitalize
end