Class: NameGenerator
- Inherits:
-
Object
- Object
- NameGenerator
- Defined in:
- lib/name-generator.rb
Constant Summary collapse
- VERSION =
'0.0.1'
- DEFAULTS =
{ :female_names => File.join(File.dirname(__FILE__),'name-generator','female-names'), :male_names => File.join(File.dirname(__FILE__),'name-generator','male-names'), :surnames => File.join(File.dirname(__FILE__),'name-generator','surnames') }
Instance Attribute Summary collapse
-
#female_names ⇒ Object
Returns the value of attribute female_names.
-
#male_names ⇒ Object
Returns the value of attribute male_names.
-
#surnames ⇒ Object
Returns the value of attribute surnames.
Instance Method Summary collapse
- #female_name ⇒ Object
- #first_name ⇒ Object (also: #middle_name)
- #full_name ⇒ Object
-
#initialize(options = {}) ⇒ NameGenerator
constructor
A new instance of NameGenerator.
- #male_name ⇒ Object
- #surname ⇒ Object (also: #last_name)
Constructor Details
#initialize(options = {}) ⇒ NameGenerator
Returns a new instance of NameGenerator.
14 15 16 17 18 19 |
# File 'lib/name-generator.rb', line 14 def initialize(={}) = DEFAULTS.merge() @female_names = [:female_names] @male_names = [:male_names] @surnames = [:surnames] end |
Instance Attribute Details
#female_names ⇒ Object
Returns the value of attribute female_names.
4 5 6 |
# File 'lib/name-generator.rb', line 4 def female_names @female_names end |
#male_names ⇒ Object
Returns the value of attribute male_names.
4 5 6 |
# File 'lib/name-generator.rb', line 4 def male_names @male_names end |
#surnames ⇒ Object
Returns the value of attribute surnames.
4 5 6 |
# File 'lib/name-generator.rb', line 4 def surnames @surnames end |
Instance Method Details
#female_name ⇒ Object
21 22 23 24 25 26 |
# File 'lib/name-generator.rb', line 21 def female_name open(@female_names) do |f| l = f.readlines l[rand(l.size)].chomp.match(/^\w+/).to_s end end |
#first_name ⇒ Object Also known as: middle_name
35 36 37 |
# File 'lib/name-generator.rb', line 35 def first_name rand(2) == 1 ? male_name : female_name end |
#full_name ⇒ Object
46 47 48 |
# File 'lib/name-generator.rb', line 46 def full_name "#{first_name} #{first_name} #{surname}" end |
#male_name ⇒ Object
28 29 30 31 32 33 |
# File 'lib/name-generator.rb', line 28 def male_name open(@male_names) do |f| l = f.readlines l[rand(l.size)].chomp.match(/^\w+/).to_s end end |
#surname ⇒ Object Also known as: last_name
39 40 41 42 43 44 |
# File 'lib/name-generator.rb', line 39 def surname open(@surnames) do |f| l = f.readlines l[rand(l.size)].chomp.match(/^\w+/).to_s end end |