Class: RealName
- Inherits:
-
Object
- Object
- RealName
- Defined in:
- lib/randexp/wordlists/real_name.rb,
lib/randexp/wordlists/male_names.rb,
lib/randexp/wordlists/female_names.rb
Class Method Summary collapse
- .female_first_names(options = {}) ⇒ Object
- .female_first_names_by_length ⇒ Object
- .first_names(options) ⇒ Object
- .load_female_first_names ⇒ Object
- .load_male_first_names ⇒ Object
- .load_surnames ⇒ Object
- .male_first_names(options = {}) ⇒ Object
- .male_first_names_by_length ⇒ Object
- .surnames(options = {}) ⇒ Object
- .surnames_by_length ⇒ Object
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( = {}) if .has_key?(:length) female_first_names_by_length[[:length]] else @@female_first_names ||= load_female_first_names end end |
.female_first_names_by_length ⇒ Object
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() case [:gender].to_s when /^male/i male_first_names() when /^female/i female_first_names() else [male_first_names(), female_first_names()].pick end end |
.load_female_first_names ⇒ Object
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_names ⇒ Object
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_surnames ⇒ Object
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( = {}) if .has_key?(:length) male_first_names_by_length[[:length]] else @@male_first_names ||= load_male_first_names end end |
.male_first_names_by_length ⇒ Object
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( = {}) if .has_key?(:length) surnames_by_length[[:length]] else @@surnames ||= load_surnames end end |
.surnames_by_length ⇒ Object
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 |