Class: RealName

Inherits:
Object
  • Object
show all
Defined in:
lib/randexp/wordlists/real_name.rb,
lib/randexp/wordlists/male_names.rb,
lib/randexp/wordlists/female_names.rb

Class Method Summary collapse

Class Method Details

.female_first_names(options = {}) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/randexp/wordlists/female_names.rb', line 12

def self.female_first_names(options = {})
  if options.has_key?(:length)
    female_first_names_by_length[options[:length]]
  else
    @@female_first_names ||= load_female_first_names
  end
end

.female_first_names_by_lengthObject



20
21
22
# File 'lib/randexp/wordlists/female_names.rb', line 20

def self.female_first_names_by_length
  @@female_first_names_by_length ||= female_first_names.inject({}) {|h, w| (h[w.size] ||= []) << w; h }
end

.first_names(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/randexp/wordlists/real_name.rb', line 23

def self.first_names(options)
  case options[:gender].to_s
  when /^male/i
    male_first_names(options)
  when /^female/i
    female_first_names(options)
  else
    [male_first_names(options), female_first_names(options)].pick
  end
end

.load_female_first_namesObject



3
4
5
6
7
8
9
10
# File 'lib/randexp/wordlists/female_names.rb', line 3

def self.load_female_first_names
  dir = File.dirname(__FILE__)
  if File.exists?("#{dir}/../../../wordlists/female_names")
    File.read("#{dir}/../../../wordlists/female_names").split
  else
    raise "words file not found"
  end
end

.load_male_first_namesObject



3
4
5
6
7
8
9
10
# File 'lib/randexp/wordlists/male_names.rb', line 3

def self.load_male_first_names
  dir = File.dirname(__FILE__)
  if File.exists?("#{dir}/../../../wordlists/male_names")
    File.read("#{dir}/../../../wordlists/male_names").split
  else
    raise "words file not found"
  end
end

.load_surnamesObject



2
3
4
5
6
7
8
9
# File 'lib/randexp/wordlists/real_name.rb', line 2

def self.load_surnames
  dir = File.dirname(__FILE__)
  if File.exists?("#{dir}/../../../wordlists/surnames")
    File.read("#{dir}/../../../wordlists/surnames").split
  else
    raise "words file not found"
  end
end

.male_first_names(options = {}) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/randexp/wordlists/male_names.rb', line 12

def self.male_first_names(options = {})
  if options.has_key?(:length)
    male_first_names_by_length[options[:length]]
  else
    @@male_first_names ||= load_male_first_names
  end
end

.male_first_names_by_lengthObject



20
21
22
# File 'lib/randexp/wordlists/male_names.rb', line 20

def self.male_first_names_by_length
  @@male_first_names_by_length ||= male_first_names.inject({}) {|h, w| (h[w.size] ||= []) << w; h }
end

.surnames(options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/randexp/wordlists/real_name.rb', line 11

def self.surnames(options = {})
  if options.has_key?(:length)
    surnames_by_length[options[:length]]
  else
    @@surnames ||= load_surnames
  end
end

.surnames_by_lengthObject



19
20
21
# File 'lib/randexp/wordlists/real_name.rb', line 19

def self.surnames_by_length
  @@surnames_by_length ||= surnames.inject({}) {|h, w| (h[w.size] ||= []) << w; h }
end